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

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

Open
alexey-sh opened this issue Sep 7, 2017 · 0 comments

Comments

@alexey-sh
Copy link

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?

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

1 participant