How to list a hasMany belongsTo relationship?


#1

I want to make a to do List with a statusbar and Teams. Each Task has Teams assigned. And for Each Team there is a Status.

My model looks like that:

//TASK model:

export default DS.Model.extend({
  taskName: DS.attr('string'),
  team: DS.hasMany('team', {async: true}),
  taskScore: DS.hasMany('taskScore', {async: true})
});

//TEAM model:

import DS from 'ember-data';

export default DS.Model.extend({
  teamName: DS.attr('string'),
  task: DS.hasMany('task'),
  taskScore: DS.hasMany('taskScore', {async: true})
});

//TASKSCORE model:

import DS from 'ember-data';

export default DS.Model.extend({
 score: DS.attr('number'),
 team: DS.belongsTo('team'),
 task: DS.belongsTo('task'),
});

Now i want to show the assigned teams to each model with their own score for the task.

This is what my template looks like:

{{#each model as |item|}}
	{{item.taskName}}
	{{#each item.team as |t|}}
		{{t.teamName}}
		{{#each t.taskScore as |s|}}
			{{s.score}}
		{{/each}}
	{{/each}}
{{/each}}

But it does not list the score for each model. It lists all scores a team has. How do I have to change the {{#each t.taskScore as |s|}}

To only list the score that belongs to the team and the task?


#2
{{#each model as |item|}}
  {{item.taskName}}
    {{#each item.taskScore as |s|}}
       {{s.team.teamName}}
       {{s.score}}
   {{/each}}
{{/each}}

Does not work for me either…


#3

Did you ever figure it out?