Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relational mapping HasMany and HasOne not working properly #109

Open
etuscano opened this issue Mar 20, 2015 · 3 comments
Open

Relational mapping HasMany and HasOne not working properly #109

etuscano opened this issue Mar 20, 2015 · 3 comments

Comments

@etuscano
Copy link

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
Copy link
Author

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

Thanks,
Elcina

@etuscano
Copy link
Author

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

@joeferner
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants