ember.jsember-model

EmberJS filter hasMany data, apply to belongsTo relationship


I have this teams model:

export default DS.Model.extend({
    "name": attr('string'),
    "players": DS.hasMany('player',{
        async: true
    })
});

along with this player model:

export default DS.Model.extend({
    "name":  attr('string'),
    "status": attr('string'),
    "team": DS.belongsTo('team',{
        async: true
    })
});

If I want to list out all the teams, easy enough. And if I want to list out all the teams, and within each team, list out all the players... also simple enough.

{{#each teams as |team index|}}
    <strong>{{team.name}}</strong></br>
    <em>Players</em>
    <ul>
    {{#each team.players as |player|}}
        <li>{{player.name}} - {{player.status}}</li>
    {{/each}}
    </ul>
{{/each}}

My QUESTION... let us say certain players are injured. If I'm looping through the teams, how would I go about ONLY displaying Teams that have injured players. If at least one player is injured, the TEAM will display, if not... the team will not display?


Solution

  • Please take a look at this twiddle