-
-
Save ptgamr/f21f653c3cec014032a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Ember from 'ember'; | |
import DS from 'ember-data'; | |
var computed = Ember.computed; | |
var get = Ember.get; | |
var RSVP = Ember.RSVP; | |
export default DS.Model.extend({ | |
name: DS.attr('string'), | |
players: DS.hasMany('player', { async: true }), | |
coach: DS.belongsTo('coach', { async: true }), | |
coachScore: computed.alias('coach.score'), | |
playersScore: computed('[email protected]', function() { | |
var promise = get(this, 'players') | |
.then(function(players) { | |
return RSVP.all(players.mapBy('score')) | |
}) | |
.then(function(scores) { | |
return scores.reduce(function(previous, current) { | |
return previous + current; | |
}, []); | |
}); | |
return DS.PromiseObject.create({ promise: promise }); | |
}), | |
score: computed('playersScore', 'coachScore', function() { | |
var playersScore = get(this, 'playersScore'); | |
var coachScore = get(this, 'coachScore'); | |
return playersScore * coachScore; | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment