Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use two different adapters at the same time in Ember.js application?

I'm using basic adapter for one API:

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

Lets say I need to retrieve some data from an other service but using REST API:

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

How to use store2 then? Or is there another approach to solve issue like this?

like image 427
Wojciech Bednarski Avatar asked May 03 '13 21:05

Wojciech Bednarski


2 Answers

You can add two different adapters, no need to create multiple stores.

For Ember 2:

Model-specific adapters can be created by putting your adapter class in an app/adapters/ + model-name + .js file of the application.

Source: DS.Adapter Class

like image 136
anthonygore Avatar answered Sep 20 '22 22:09

anthonygore


When you need to use a different Store, define your Store and then specify the Model you want to retrieve:

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

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

// retrieving from custom store
var myModelObject = App.store2.find(App.MyDifferentModel, 1);

// retrieving from defaultStore is implicit for the Models defined
var post = App.Post.find(1);

hope it helps

like image 27
intuitivepixel Avatar answered Sep 20 '22 22:09

intuitivepixel