node-persist icon indicating copy to clipboard operation
node-persist copied to clipboard

Relational mapping HasMany and HasOne not working properly

Open etuscano opened this issue 10 years ago • 3 comments

Hi, In our company we are trying to migrate few applications from java to node js . As part of the ORM we choose to use node -persist seeing lot of valuable features and it will go long way...

after doing the relational one to many and many to many mapping we found result is not retrieving properly from database.

we created tables in database

CREATE TABLE Person ( ID int NOT NULL, NAME varchar2(1000) , PHONE_ID int NOT NULL, PRIMARY KEY (PHONE_ID) );

CREATE TABLE Phone ( ID int NOT NULL PRIMARY KEY, PHONE_ID int NOT NULL, PHONE_NUMBER int NOT NULL, CONSTRAINT PHONE_ID FOREIGN KEY (PHONE_ID) REFERENCES Person(PHONE_ID) );

node js code

var persist = require('persist'); var type = persist.type; Phone = persist.define("Phone", { "id": { type: type.INTEGER, dbColumnName: 'ID',primaryKey:'ID' },"PHONE_ID": { type: type.INTEGER, dbColumnName: 'PHONE_ID' },"phone_number": { type: type.INTEGER, dbColumnName: 'PHONE_NUMBER' } }, { "tableName": "PHONE" }); Person = persist.define("Person", { "id": { type: type.INTEGER, dbColumnName: 'ID' }, "name": { "type": type.STRING, dbColumnName: 'NAME' },"PHONE_ID": { type: type.INTEGER, dbColumnName: 'PHONE_ID',primaryKey:'PHONE_ID' } }, { "tableName": "PERSON" }).hasMany(Phone,{foreignKey:'PHONE_ID'});

persist.connect({ "driver": "oracle", "name": "xxxxxx", "hostname": "xxxxxxxxx", "user": "ecee_int", "password": "xxxxxx", "port": "1521", "database": "xxxxx", "pooling": { "name": "xxxxxxx", "max": 2, "min": 1, "idleTimeoutMillis": 30000 } }, function(err, connection) { Person.using(connection).all(function(err, person) { person.phones.orderBy('number').all(function(err, phones) { console.log(JSON.stringify(phones)); }); });

});

but the result returned is [{"phones":{},"id":1,"name":"karthik"},{"phones":{},"id":2,"name":"asuthos"},{"phones":{},"id":3,"name":"peter"}]

which don't have associated phones kindly suggest us what is wrong here ?

thanks Elcina

etuscano avatar Mar 20 '15 18:03 etuscano

Hi, This is bit important for our organization. Please help us if you have any suggestions.

Thanks, Elcina

etuscano avatar Mar 22 '15 23:03 etuscano

Hi , Kindly reply to our issue when you have some time, we have couple of developers waiting for your reply :-( .The many to many mapping is very important to us to choose persist as our ORM for multiple applications.

thanks, Elcina

etuscano avatar Mar 24 '15 18:03 etuscano

I am no longer maintaining persist. If you would like to take over the maintenance I would be happy to transfer ownership to you.

joeferner avatar Mar 24 '15 18:03 joeferner