Created
June 20, 2016 08:10
-
-
Save balinterdi/70db56f7a6c632f4ea4be88f9e0a5f7b to your computer and use it in GitHub Desktop.
Composing `friendships` from the constituent parts - doesn't work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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