I have a user model that has 2 relationships (myFriends and friendsWithMe). An intersection is an array of users that represents real friends. I solved this computatation using RSVP.all:
friends: function() {
var ret = [];
Ember.RSVP.all([this.get('myFriends'), this.get('friendsWithMe')]).then(function(results) {
ret.pushObjects(_.intersection(results[0].get('content'), results[1].get('content'))) ;
});
return ret;
}.property('myFriends.@each', 'friendsWithMe.@each'),
Now the problem is that I have another computed property that depends on this:
myFriendshipStatus: function() {
if(this.get('friends').contains(this.container.lookup('user:current'))){
return 2;
} else if(this.get('friendsWithMe').contains(this.container.lookup('user:current'))){
return 4;
} else if(this.get('myFriends').contains(this.container.lookup('user:current'))){
return 1;
} else if (this.get('id') === this.container.lookup('user:current').get('id')){
return 3;
} else {
return 0;
}
}.property('friends.@each')
When I debug myFriendShipStatus, promises are not allowed, and there are no entries in the friends array.
I also tried changing the function of my friends to ember.computed.intersect, which would look like this:
friends: function() {
return Ember.computed.intersect('myFriends', 'friendsWithMe')
}.property('myFriends.@each', 'friendsWithMe.@each'),
But then I get an exception from this line:
if (. This.get ('friends') contains (this.container.lookup ('user: current'))) {
Since ArrayComputedProperty does not have a function, it contains.
myFriendShipStatus? Ember.computed.intersect, , .