Open testuser2015 opened 9 years ago
By using Animal.hasOne('owner', Person)
, you are creating the owner_id
in the animal
table as you said.
This means that each 'owner' can have many animals.
Using something like personInstance.getAnimals()
should return the animals for the owner.
You have a one-to-many relationship as that Person
has many Animals
, and Animal
hasOne
Person
.
Is it possible to add Associations (hasOne) in mongoDb using orm module. In your examples only used mysql, postgresql only, I think that it is not possible with mongodb. But i am bit confused that anywhere in the document not mentioned about mongo db relation.
Please tell me, how to achieve one to many relation .
var Person = db.define('person', { name : String }); var Animal = db.define('animal', { name : String }); Animal.hasOne("owner", Person); // creates column 'owner_id' in 'animal' table if it is possible ,please explain it with model.create()
otherwise please explain how to achieve this with mongodb as database.
Please help me it is very urgent.....