Ember-data使用parent查找嵌套模型

时间:2013-03-15 03:51:28

标签: ember.js ember-data

我如何告诉Ember不仅要检索匹配列表,还要为每个相关的玩家获取对象?

在我的路由器中,我有:

App.MatchesRoute = Ember.Route.extend
  model: ->
    App.Match.find()

以下是我的localhost:3000/matches.json

的JSON数据
{"matches":[{"id":1,"player_one":{"id":1,"name":"Lex"},"player_two":{"id":20,"name":"Superman"}}]}

更新以提供更多信息03/15/13

这是matches.emblem(徽章像手杖一样瘦小的把手)

#matches
  each match in controller
    linkTo "match" match class="panel six columns"
      p Match between {{match.player_one.name}} and {{match.player_two.name}}

我们成功获取Match个对象,我可以在其上调用id(未显示),但我们需要获取match.player_one和{{1}的名称},返回undefined。

匹配

match.player_two

播放器

App.Match = DS.Model.extend
  player_one: DS.belongsTo('App.Player')
  player_two: DS.belongsTo('App.Player')

1 个答案:

答案 0 :(得分:0)

如果你总是让比赛中的球员回归,你可能想要将球员宣布为嵌入球员。

你会写这样的东西:

Adapter.map(App.Match, {
  player_one: {embedded: load},
  player_two: {embedded: load},
});