2
votes

The problem is that we are using embedded records in our mongo database and trying to load those same records in our ember.js datastore on the front end. This works fine when we load the document directly but not when we sideload it.

On the ember side we have the corresponding models and the following to support embedded records

App.RateSerializer = App.ApplicationSerializer.extend( DS.EmbeddedRecordsMixin, {
    attrs: {
      tiers: { embedded: 'always' }
    },
});

Now every time we load the rate object directly, the embedded tiers are serialized correctly which is great! Except, to speed up the app we like to sideload the rates.

Now our problem is that when we sideload the object all the embedded objects aren't serialized correctly because ember doesn't call the extractArray function that the RateSerializer overrides in the ApplicationSerializer.

What is the correct way of setting up per-type serializers when sideloading?

1

1 Answers

0
votes

I got it working by calling the sideloaded type's serializer manually from the extract method of the serializer.

For example, I have a user that sideloads accounts. In the user serializer, I create an account serializer and call its normalizePayload:

extract: function(store, type, payload, id, requestType) {
    if (payload.accounts) {  // has sideloaded account data
        payload = AccountSerializer.create().normalizePayload(payload);
    }
    return this._super(store, type, payload, id, requestType);
},