@Schnodderbalken wrote:
I am trying to use a promise inside of a computed property. I need that because I want dynamic suggestions to be rendered when several selections are made by the user.
In order to make handlebars be able to handle it I wrapped a DS.PromiseArray around the promise.tag_suggestions: function() { var tag_ids = []; var chosenTags = this.get('chosenTags'); chosenTags.forEach(function(chosenTag) { tag_ids.push(chosenTag.get('id')); }); var component = this; // all of this returns a promise, but Handlebars can't handle the promise var promise = this.get('store').query('smartgroup/tag_suggestion', {'tag_ids': tag_ids}).then(function(tagSuggestions) { tagSuggestions = tagSuggestions.toArray(); tagSuggestions = tagSuggestions.sortBy('count', 'desc').reverse(); return tagSuggestions.slice(0, 5); }); // that's why I need to create a promise array return DS.PromiseArray.create({ promise: promise }); }.property('chosenTags'),
This made everything work.
The problem is: I work with the rendered object and eventually send it back to the backend together with other rendered objects. What Ember tells me when I try to do is:Assertion Failed: All elements of a hasMany relationship must be instances of DS.Model, you passed [,,<(subclass of Ember.ObjectProxy):ember779>]
The first two objects have the correct type. The one that results of the resolved promise is of a subclass of Ember.ObjectProxy. Any ideas how to solve this problem?
Posts: 1
Participants: 1