1
votes

this is ember rc1 master as of march 25, and ember-data rev 12. i can't get a Model's hasMany to sideload - that sideloaded data doesn't materialize in the store. using the default RESTAdapter.

  App.AssetLinkGroup = DS.Model.extend({
      asset_links : DS.Model.hasMany('App.AssetLink')
  })
  App.AssetLink = DS.Model.extend({
      asset_link_group : DS.Model.belongsTo('App.AssetLinkGroup')
  })

the json i'm returning from the server for App.AssetLinkGroup.find(5) is as follows (with a lot of the basic attributes like name/date/etc removed for brevity)

 {
 "asset_link_group": {

      "asset_link_ids": [154,155],

      "asset_links": [
           {
                id : 154,
                "asset_link_group_id": 5
           },
           {
                id : 155,
                "asset_link_group_id": 5
           }
      ]
   }
 }

App.AssetLinkGroup.find(5) successfully loads the AssetLinkGroup model from the server. but the AssetLinks don't seem to get materialized in the store. when i try an App.AssetLink.all() .content, it shows an empty array.

furthermore if i try:

var algroup5 = App.AssetLinkGroup.find(5);
algroup5.get('asset_links');

it makes a findMany call to the server which shows me it definitely doesn't have these records in the store.

why aren't the AssetLink records materializing in the store when i load AssetLinkGroup?

2

2 Answers

4
votes

I'd say that the asset_links array in the JSON should be at the root level.

{
 "asset_link_group": {
   "asset_link_ids": [154,155]
 },
 "asset_links": [
   {
      id : 154,
      "asset_link_group_id": 5
   },
   {
       id : 155,
       "asset_link_group_id": 5
   }
  ]
 }
0
votes

Have you configured your adapter to sideload the records in asset_links? Assuming you are using RESTAdapter, you would do something like this:

DS.RESTAdapter.configure('App.AssetLink',
    sideloadAs: 'asset_links'
);