You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
From the documentation:
Here is my essential(pseudocode):
Any thoughts?
The text was updated successfully, but these errors were encountered: