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

Removing references from parents when using destroy [optional] #114

Merged
merged 2 commits into from
Feb 26, 2014
Merged

Removing references from parents when using destroy [optional] #114

merged 2 commits into from
Feb 26, 2014

Conversation

nibrag
Copy link
Contributor

@nibrag nibrag commented Feb 25, 2014

var Foo = Backbone.AssociatedModel.extend({});

var Bar = Backbone.AssociatedModel.extend({
       relations: [{
       type: Backbone.One,
            key: 'rel',
            relatedModel: Foo
       }]
});

Create some instances:

var foo = new Foo;

var bar = new Bar({rel: foo1});

Now foo.parents contains one element (bar).
Next, destroy bar.

bar.destroy()
// foo.parents.length => 1

As you can see, after the removal of foo, parents.length not changed. This is normal, since foo can be used later.

bar.save({rel: foo})

But there are cases when bar is no longer used and bar must be removed from foo.parents.

This PR helps to solve this problem.

bar.destroy({remove_references: true}) // default true
// foo.parents.length => 0

dhruvaray added a commit that referenced this pull request Feb 26, 2014
Removing references from parents when using destroy [optional]
@dhruvaray dhruvaray merged commit 637ea84 into dhruvaray:master Feb 26, 2014
@dhruvaray
Copy link
Owner

@MrADM : Thanks! This is perfect! Much appreciated.

@dhruvaray dhruvaray self-assigned this Feb 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants