Guilherme Aiolfi
Guilherme Aiolfi

Reputation: 45

Sideloading and sideloadAs in ember-data

So, I'm trying to sideload records in ember-data. My models are something like:

App.Product = DS.Model.extend({
     name: DS.attr('string'),
     category_ids: DS.hasMany('App.Category')
});
App.Category = DS.Model.extend({
    title: DS.attr('string')
});

I'm configuring the sideload feature as follows:

App.store.adapter.serializer.configure(App.Category,
    { 
         sideloadAs: 'categories' 
    });
  1. It works as long the name of my field is "category_ids". Any other name won't work. Is there a way to rename it and keep it working?
  2. Since the configuration is done in the resource/model, it doesn't seem to have any way to sideload records for categories when loading products and NOT sideloading categories when loading "Posts". In case both use the same Category resource. is that right?

Upvotes: 0

Views: 1606

Answers (1)

ken
ken

Reputation: 3745

You maybe able to provide the proper mappings for it in the adapter. I'm not sure though. You should provide a sample of your code to better help you.

App.store = DS.Store.create({
    revision: 11,
    adapter: DS.RESTAdapter.create( {
        mappings: {
            categories: 'App.Category'
        },
    })
});

Upvotes: 1

Related Questions