I am trying to figure out Ember Data models and try to assign a collection of found objects using store.findAll() for the hasMany relation of the ember data model.
I have two models:
App.Leaf = DS.Model.extend({ text: DS.attr('string'), branch: DS.belongsTo('App.Branch') }); App.Branch = DS.Model.extend({ lotsOfLeaves: DS.hasMany('App.Leaf') });
If I assign a link as part of createRecord()
App.store.loadMany(App.Leaf,[ { id: 1, text: "Hello, I'm leaf 1", branch_id: 1 }, { id: 2, text: "Hello, I'm leaf 2", branch_id: 1 } ]); var allLeaves = App.store.findAll(App.Leaf); var oneBranch = App.Branch.createRecord({ id: 1, lotsOfLeaves: allLeaves });
then it fails (silently) since oneBranch.get('lotsOfLeaves.length') is 0 .
Similarly, it fails if I assign a connection after association:
var all = App.store.findAll(App.Leaf); oneBranch.set('lotsOfLeaves', all);
I understand that I can use pushObject() on oneBranch.get('lotsOfLeaves') to add each sheet individually, but is this the only way?
source share