I am having trouble defining a computed property, based on some async associations, in the object controller. I based my example on some examples I found here and in the Ember docs.
I have three (relevant) models: A Space
with one or more Subscription(s)
, which each have a User
. They are all loaded async
:
MyApp.Space = DS.Model.extend({
name: DS.attr('string'),
subscriptions: DS.hasMany('subscription', { inverse: 'space', async: true })
});
MyApp.Subscription = DS.Model.extend({
space: DS.belongsTo('space', { inverse: 'subscriptions', async: true }),
user: DS.belongsTo('user', { async: true })
});
MyApp.User = DS.Model.extend({
name: DS.attr('string')
});
I try to compute a property mySubscription
, which gets the subscription belonging to me from subscriptions
, in the controller for the space because that is where I have access to the current user through a mixin
(not particularly relevant for this example).
MyApp.SpaceController = Ember.ObjectController.extend(
MyApp.CurrentUserMixin, {
mySubscription: function () {
var me = this.get('currentUser');
var subscriptions = this.get('model.subscriptions');
return subscriptions.findBy('user', me);
}.property('model.subscriptions.@each')
});
This property always turns out to be undefined
however I try it. I've tried adding .content
to everything async, I tried finding by id
and debugged and inspected the hell out of it. Somehow, I am not able to find anything within the array of associated objects. Anybody got an idea how I should proceed?
subscription
association on the user?user
might holdsubscriptions
to multiplespaces
so we would end up at the same point I think (having to search the user subscriptions for a specific space..)