javascript - Need ember model to return array promise not object -
i trying return array promise model can loop through results in template. need contact products return promise array , not promise object.
model :
app.contacteditorroute = ember.route.extend({ model: function (params) { return ember.rsvp.hash({ contact: this.store.find('contact', params.id), /*need return array not object does*/ contactproducts: this.store.find('contactproduct',params.id), products: this.store.find('product') }) }
template: (using emblem markup)
each contactproduct in contactproducts p ' quantity contactproduct.quantity ' notes contactproduct.note
if want array way have code structured, can do
contactproducts: this.store.find('contactproduct',params.id) .then(product => [product])
this approach take when want additional processing on result of find
, yet still return promise model
designed do.
however, poster indicated not want doing. if contact products hasmany
property of contacts, there (or perhaps fetched based on {async: true}
).
if contacts has no hasmany('contactproduct')
, may need fetch them yourself, doubt if contact products have same id contacts. if do, shouldn't. model ids should unique. assuming contact products have belongsto
pointing contact
want this:
contactproducts: this.store.find('contactproduct', { contact: params.id })
which will return (promise for) array.
however, in general in such cases it's better put additional retrieval in aftermodel
hook. allows keep model
nice , clean.
Comments
Post a Comment