Closed lukasbuenger closed 10 years ago
There seems to be something strange going on when overriding idAttribute
in custom nested models:
var obj = {
id: 'a1',
foo: [
{ my_id: 'b1', bar: 'baz' }
]
};
var CustomCollection = Backbone.DocumentCollection.extend({
model: Backbone.DocumentModel.extend({
idAttribute: 'my_id'
})
});
var Model = Backbone.DocumentModel.extend({
getNestedCollection: function(key, value, opts) {
switch (key) {
case 'foo':
return new CustomCollection(value, opts);
break;
default:
return new Backbone.DocumentCollection(value, opts);
break;
}
}
});
For one thing, options
(or opts
in my example) always seems to contain an idAttribute
attribute, which overrides the custom model's definition. If I change or delete that, things break down quickly, e.g. the collection contains only the first model and all subsequent ones are missing.
Haven't pinned this one down yet, help in fixing this would be appreciated. Should I open a separate issue for this?
Addresses #14: I tried to follow your coding style as close as possible. I'd love to have this feature available. If you want some things changed or tested or whatever, just let me know.