0
votes

I've tried to retrieve some data using ember-data. But there is just artists: undefined when I look in the console the model object retrieved.

I don't understand why the association is not done, here is my code

MyApp.Track = DS.Model.extend
    artists: DS.hasMany 'MyApp.Artist'
    name: DS.attr 'string'

MyApp.Artist = DS.Model.extend
    name: DS.attr 'string'

And there is the data should be loaded :

{
    "track": {
    "name": "Troublemaker",
    "id": 74,
    "artists": [
        {
            "artist": {
                 "name": "Taio Cruz"
            }
        }
    ]
  }
}

I've got the name of the track but not the id and the artistsdata.

Thanks a lot for your help.

1

1 Answers

1
votes

you have to return the ids of the artist as artist_ids array

here's the documentation of that http://emberjs.com/guides/models/the-rest-adapter/#toc_relationships

Also if you plan to make a one ajax request you have to include the id of the artist for this to work http://emberjs.com/guides/models/the-rest-adapter/#toc_sideloaded-relationships

If your back-end is on rails you have to include the ID in the model serializer like this:

class TrackSerializer < ActiveModel::Serializer
  attributes :id, :name, :actist_ids
end