Skip to content

Instantly share code, notes, and snippets.

@balinterdi balinterdi/person.js
Created Jun 20, 2016

Embed
What would you like to do?
Composing `friendships` from the constituent parts - doesn't work
export default Model.extend({
name: DS.attr(),
frienderFriendships: DS.hasMany('friendship', { inverse: 'friender' }),
friendedFriendships: DS.hasMany('friendship', { inverse: 'friended' }),
friendships: Ember.computed('frienderFriendships', 'friendedFriendships', function() {
let friendedFriendshipsRel = this.hasMany('friendedFriendships');
let frienderFriendshipsRel = this.hasMany('frienderFriendships');
let frienderFriendships;
if (frienderFriendshipsRel.value() !== null) {
frienderFriendships = this.get('frienderFriendships');
} else {
frienderFriendships = frienderFriendshipsRel.load();
}
let friendedFriendships;
if (friendedFriendshipsRel.value() !== null) {
friendedFriendships = this.get('friendedFriendships');
} else {
friendedFriendships = friendedFriendshipsRel.load();
}
return Ember.RSVP.all([frienderFriendships, friendedFriendships]).then(([frienders, friendeds]) => {
return frienders.concat(friendeds);
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.