Git Product home page Git Product logo

Comments (6)

CraigLRussell avatar CraigLRussell commented on August 22, 2024

Hi David,

Can you try including the primary key in your projections?

var orderProjection = new jones.Projection(Orders).
addField(“id_user”, “id_order”, “cost”);

var customerProjection = new jones.Projection(Customers).
addField(, “id”, "name”).
addRelationship("orders", orderProjection);

Regards,

Craig

On Aug 9, 2016, at 4:03 PM, davidteofilovic [email protected] wrote:

Hey guys,

I replicated my issue using 2 simple tables running on MySQL Cluster. Here is the SQL I used to create the tables, along with the table mappings code and the result I get from node.

Background Info

Running the latest version of mysql-js
Node Version v0.12.2
MySQL Cluster Version 7.5.3
MySQL Cluster

Customers Table
CREATE TABLE 'graph' . 'customers' (
'id' INT NOT NULL COMMENT '',
'name' VARCHAR(45) NOT NULL COMMENT '',
'age' INT NOT NULL COMMENT '',
PRIMARY KEY('id') COMMENT '')
ENGINE=NDBCLUSTER
PARTITION BY KEY(id)

Orders Table
CREATE TABLE 'graph' . 'orders' (
'id_user' INT NOT NULL COMMENT '',
'id_order' VARCHAR(45) NOT NULL COMMENT '',
'cost' INT NOT NULL COMMENT '',
PRIMARY KEY('id_user', 'id_order') COMMENT '',
FOREIGN KEY (id_user) REFERENCES customers(id))
ENGINE=NDBCLUSTER
PARTITION BY KEY(id_user);

Customers has a one-to-many relationship with Orders

App.js

"use strict";
var jones = require("/api_tests/mysql-js/database-jones/");
var connectionProperties = new jones.ConnectionProperties("ndb");

function Customers(id, name, age) {
if(id !== undefined) {
this.id = id;
this.name = name;
this.age = age;
}
}

function Orders(id_order, cost) {
if(id_order !== undefined) {
this.id_order = id_order;
this.cost = cost;
}
}

function mapCustomers() {
var customerMapping = new jones.TableMapping("customers");
customerMapping.mapField("id");
customerMapping.mapField("name");
customerMapping.mapField("age");

    customerMapping.mapOneToMany({
        fieldName: "orders",
        target: Orders,
        targetField: "id_user"
    });

customerMapping.applyToClass(Customers);

}

function mapOrders() {
var orderMapping = new jones.TableMapping("orders");
orderMapping.mapField("id_order");
orderMapping.mapField("cost");

    orderMapping.mapManyToOne({
        fieldName: "id_user",
        target: Customers,
        foreignKey: "fk_id"
    });

orderMapping.applyToClass(Orders);

}

function mapShop() {
mapCustomers();
mapOrders();
}

mapShop();

var orderProjection = new jones.Projection(Orders)
.addField("cost");

var customerProjection = new jones.Projection(Customers)
.addField("name")
.addRelationship("orders", orderProjection);

var onFind = function(err, result) {
if (err) { console.log(err);} else {
console.log(result);
}
};

jones.openSession(connectionProperties).then(
function(session) {
session.find(customerProjection, {id: 4}, onFind);
}
);
When I run this inside node, I get the following error:
this.keyRecord = indexHandler.dbIndex.record;
^
TypeError: Cannot read property 'dbIndex' of null
at new NdbProjection (/api_tests/mysql-js/jones-ndb/impl/ndb/NdbProjection.js:76:37)

Might be worth mentioning that I can pass in a table name inside session.find and have the correct result returned to me. However, no matter what I try when I pass in a projection, I always end up with the error above. Please let me know if you need any more information. Thanks!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #36, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWlpvDAwCVsFl_YUs0G4BnFvcGHvoESks5qeQdbgaJpZM4JgnA5.

Craig L Russell
Architect
[email protected]
P.S mailto:[email protected]. A good JDO? O, Gasp!

from mysql-js.

davidteofilovic avatar davidteofilovic commented on August 22, 2024

Hi Craig,

I tried that and got the following error:

{ [Error: Bad projection for Orders: fieldid_user must not be a relationship] sqlstate: 'HY000' }

from mysql-js.

clr-apache avatar clr-apache commented on August 22, 2024

The relationships are "virtual" as far as the table is concerned. So you can't have both column id_user and relationship id_user.
That's what the Error message is supposed to mean. You could suggest an error message that would make this more obvious.
If you look at database-jones/test/composition/lib.js what you are trying to do is exactly the relationship between ShoppingCart and LineItem. LineItem has a compound primary key with one of the key columns also defining the foreign key to ShoppingCart.

from mysql-js.

davidteofilovic avatar davidteofilovic commented on August 22, 2024

I changed the field name and the Projection API worked for this little example! Thank you so much!
However, for my actual project, I was also stuck at the "Bad Projection" error and tried to implement the same fix, but got a segmentation fault with no other error before that. Do you want me to post the code for that as well?

from mysql-js.

CraigLRussell avatar CraigLRussell commented on August 22, 2024

Just to avoid confusion, can you close this one and open a new bug report?
It might be good for you to try with the mysql adapter as well as the ndb adapter. All you should need to do is to change jones.ConnectionProperties("ndb") to jones.ConnectionProperties("mysql"). They should work the same.
Thanks!

from mysql-js.

davidteofilovic avatar davidteofilovic commented on August 22, 2024

I will close this bug report after this last comment and start a new one. Just before I do that, I want to say that I tried to change the ConnectionProperties from 'ndb' to 'mysql' and that brought in new errors.

from mysql-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.