dagda1
dagda1

Reputation: 28810

ember-data mappings for sideloading revision 11

What has happened to mappings to the revision 11 ember-data with regard to sideloading?

I have the following 2 model classes:

WZ.Exercise = WZ.Model.extend
  name: DS.attr 'string'
  description: DS.attr 'string'
  group: DS.belongsTo('WZ.Group', {key: 'groups'})  #I don't think the key does anything

WZ.Group = WZ.Model.extend
  name: DS.attr 'string'
  exercises: DS.hasMany('WZ.Exercise')

Previously I had a mappings property on the adapter which no longer seems to do anything:

WZ.Store = DS.Store.extend
  revision: 11
  adapter: DS.RESTAdapter.create
    bulkCommit: false
    mappings:
      groups: WZ.Group

The sideloading code expects the sideloaded root json property to be the same as the property name:

for (var prop in json) {
  if (!json.hasOwnProperty(prop)) { continue; }
  if (prop === root) { continue; }
  if (prop === this.configOption(type, 'meta')) { continue; }

  sideloadedType = type.typeForRelationship(prop);

I don't see anyway to get round this. Either the json is in the state the code expects or it will not work.

Upvotes: 1

Views: 725

Answers (2)

Shreyans
Shreyans

Reputation: 881

This is how I sideload data:

DS.RESTAdapter.configure('App.Groups', {
    sideloadAs: 'groups'
});

App.Store = DS.Store.extend({   
    revision: 11,
    adapter: DS.RESTAdapter.create({})   
});

Upvotes: 2

Mikus
Mikus

Reputation: 1

I encountered a similar problem and found a mapping in the ember_data_example project that resolved it for me. In my case, a ticketEntries: hasMany('App.TicketEntry') was not loading.


    // Prepare our global Ember Data 'store'
    App.RESTSerializer = DS.RESTSerializer.extend({
      init: function() {
        this._super();

        this.map('App.Ticket', {
          creator: {embedded: 'always'},
          ticketEntries: {embedded: 'always'}
        });
      }
    });

    App.Adapter = DS.RESTAdapter.extend({
      bulkCommit: false,
      serializer: App.RESTSerializer.create()
    });

    App.Store = DS.Store.extend({
      revision: 11,
      adapter: App.Adapter.create()
    });

    App.store = App.Store.create(
    );

Upvotes: 0

Related Questions