ember.js - ember / ember-data belongsTo and hasMany not updating as expected -
i have 2 models:
app.focusarea = ds.model.extend definition: ds.attr('string') theme: ds.belongsto('theme', async: true ) app.theme = ds.model.extend definition: ds.attr('string') focusareas: ds.hasmany('focusarea', async: true ) when creating 1 of each, associate focus area theme
theme = store.createrecord("theme", id: 3 definition: 'theme definition' ) focusarea = store.createrecord("focusarea", id: 4 definition: 'focusarea definition' ) theme.get("focusareas").then (focusareas) -> focusareas.pushobject focusarea theme.save() but when run tests
theme.get('focusareas').then (focusareas)-> expect(focusareas.toarray.length).to.equal(1) it fails - focusareas.toarray.length equals 0, in other words, association failed. doing wrong or missing? help appreciated.
update:
figured out, theme.get('focusareas') returns unresolved promise, 0, when resolved homecoming 1 eg:
focusareas = theme.get('focusareas') focusareas.then -> console.log focusareas.get('length') #=1 or
store.find('theme', 4).then (theme)-> theme.get('focusareas').then -> expect(theme.get('focusareas').get('length')).to.equal(1) in other words
store.find('theme', 4).then (theme)-> theme.get('focusareas').then -> theme.get('focusareas').foreach (item) -> console.log(item.get('definition')) #'focusarea definition' item.get('theme').then -> console.log(item.get('theme').get('definition')) #'theme definition' i guess should rtfm!
during object init need assign focusareas sort of collection getters , setters can work . arrayproxy work nicely in case. how 1 can sort items automagically with?
theme = store.createrecord("theme", id: 3 definition: 'theme definition', focusareas: ember.arrayproxy.createwithmixins ember.sortablemixin, content: [], sortproperties: ['id'], // set object property sortascending: true ) hope helped!
ember.js ember-data
No comments:
Post a Comment