Skip to content

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

@alexey-sh

Description

@alexey-sh

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions