dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 376 forks source link

Reverse association doesn't clear all entities associated with the model #806

Open alexey-sh opened 7 years ago

alexey-sh commented 7 years ago

From the documentation:

Sometimes you want to be able to access an association from the opposite model. In the case of the example above, from the Person. You can do this by passing an option to the association.

Animal.hasOne('owner', Person, { reverse: "pets" }); After this, every person has now 2 convenience methods:

getPets(callback) - get all animals associated with the person setPets(cat, dog, callback) - clear all animals associated with the person and then add cat and dog

Here is my essential(pseudocode):

Contact.hasOne('person', Person, { reverse: "contacts" })
Person.create({name: 'ha', contacts: [{phone: '123'}, {phone: '123'}]})
// wait for the request
person = Person.get(1);
contact = Contact.create({phone: 'asd'});
person.setContacts(contact);
// now there are two contacts in database. but I expected only one with "asd" phone

Any thoughts?