Comments (6)
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 ClusterCustomers 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.
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.
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.
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.
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.
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)
- Parameterized test cases HOT 1
- jones-ndb: V8 API deprecation warnings with node 6.3.1 HOT 2
- Segmentation Fault with Projection API HOT 25
- jones-ndb: assertion fails on getNoOfBlobColumns HOT 2
- jones-ndb should support partition key distinct from primary key
- Cannot build jones-ndb with node 7.x HOT 5
- Deprecation warnings building jones-ndb with node 6.9.1 HOT 2
- openSession should work without mappings HOT 1
- createTable should work without a constructor HOT 1
- Create UUID columns from meta.char(XX).generated()
- Session should support oneShot operation HOT 4
- Support table mapping for table name function variants HOT 1
- Undefined symbol __ZN15NdbQueryBuilder7prepareEv
- setLockMode is not implemented
- Split jones-ndb into two modules
- jones-ndb 7.6 cannot connect to NDB 8.x HOT 1
- jones-ndb build failure with current mysql-trunk
- jones-ndb build failure HOT 2
- How can I retrive UUID from MySQL in my Flutter app?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mysql-js.