-
Notifications
You must be signed in to change notification settings - Fork 72
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
Object references seem to get broken after collection.set #67
Comments
I realised the test case didn't capture the problem correctly so have updated it. Im beginning to suspect the problem is due to the base object being a Collection rather than a Model - sound plausible? |
I tried an alternate test that wraps the structure in a Model (as a possible workaround) but this also fails. test("nested set shouldnt destroy references - take 2", function () {
var Employees = Backbone.Collection.extend({
model:Employee
}),
Team = Backbone.AssociatedModel.extend({
relations: [
{
type: Backbone.Many,//nature of the relation
key: 'employees',
collectionType: Employees, //Collection to be used.
relatedModel: Employee //Optional
}
],
defaults: {
}
}),
json1 = {
id:'t1',
employees:[
{
id:'e1',
fname: "John",
manager: {
id:'m1',
fname:'Mikeeee'
}
}
]
},
json2 = {
id:'t1',
employees:[
{
id:'e1',
fname: "John",
manager: {
id:'m1',
fname:'Mike' //<----- changed
}
}
]
};
var team = new Team(json1);
var manager1 = team.get('employees[0].manager');
team.set(json2);
//re-resolving reference will get new value as expected
equal(team.get('employees[0].manager.fname'), 'Mike');
//Fails: direct reference to manager object will return old value
equal(manager1.get('fname'), 'Mike');
}); |
Thanks for the elaborate test case(s) and catching this. d13243c fixes the scenarios you have submitted. They are now part of the test suite as well. Let me know if it works for you. |
Wow, and thank you very much for what is probably the quickest fix Ive ever received for an issue Ive raised :D ! Works great. |
Thank you! If you are curious, the fix essentially involved not creating a new model when a model with the same id value is passed from outside. It was handled for collections in issue #31. But I had somehow missed this case. I took the opportunity to simply the logic while I was fixing this case. Lastly, if you like our library, please don't forget to share your appreciation by starring us! |
All happy + starred. Cheers, |
Hi, we've been evaluating bb-associations for use in our webapp but think there's an issue with objects being recreated when setting via blobs of json. Ive seen issue #31 but think there's still a problem there. Here's a test case that I believe demonstrates the problem ;
To give a bit more context - We have a rich model/collection hierarchy thats; a) used to drive a number of nested Marionette CollectionViews/CompositeViews etc and b) can be periodically updated in part or whole by large blobs of json. So it's important that references aren't broken to avoid UI re-draws.
Any thoughts?
Cheers,
Greg
The text was updated successfully, but these errors were encountered: