Closed janispauls closed 10 years ago
Not automatically. But possible:
var model = new SomeModel();
model.set({childModels: [model]});
console.log(model.get('childModels'))
Full snippet would be:
var SomeModel = Backbone.AssociatedModel.extend({
relations: [{
type: Backbone.Many,
key: 'childModels',
relatedModel: function(){ // pass function or string
return SomeModel;
}
}],
defaults: {
childModels: [],
name: 'test'
}
});
model = new SomeModel();
model.set({childModels: [model]});
console.log(model.get('childModels'));
Let me know if it helps.
Thank you. I was trying to put 'relations' key as a function not 'relatedModel'. Seems it will work fine.
:thumbsup:
Example - http://jsfiddle.net/janispauls/PB62k/