How can I tell Ember to retrieve not only a list of matches, but also get objects for each of the players associated?
In my router, I have:
App.MatchesRoute = Ember.Route.extend
model: ->
App.Match.find()
Here is what my JSON data is for localhost:3000/matches.json
{"matches":[{"id":1,"player_one":{"id":1,"name":"Lex"},"player_two":{"id":20,"name":"Superman"}}]}
Update to provide more info 03/15/13
Here is the matches.emblem
(Emblem being the haml-slim-like-handlebars)
#matches
each match in controller
linkTo "match" match class="panel six columns"
p Match between {{match.player_one.name}} and {{match.player_two.name}}
We are successfully getting the Match
objects, and I can call the id
on it (not shown), but we need to get the names of match.player_one
and match.player_two
, which are returning undefined.
Match
App.Match = DS.Model.extend
player_one: DS.belongsTo('App.Player')
player_two: DS.belongsTo('App.Player')
Player
App.Player = DS.Model.extend
name: DS.attr('string')
Player
model has to reference theMatch
with abelongsTo
as well. And you'd have to tell your adapter to embed the child object. Something like:DS.RESTAdapter.map( 'App.Match', { player_one: { embedded: 'load' } });
... something like this.. but I'm not 100% sure of how to properly do this, I just know it's something along these lines (I use a modified version of the adapter) – MilkyWayJoe