Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify a Store on a Ember js model?

Tags:

ember.js

I am trying to use multiple stores in Ember because I have namespaced models on the api side.

Aka

App.Gl.Account = DS.Model.extend //Needs to route to /gl/accounts

App.Company = DS.Model.extend //Routes to /companies

My first thought was to define a namespace

App.Gl = Ember.Namespace.create({});
//and a store
App.Gl.Store = DS.Store.extend({adapter:DS.RESTAdapter({namespace:'gl'})});
App.Store = DS.Store.extend({adapter:DS.RESTAdapter})

problem is the model is automatically binded to the App.Store.

Any other suggestions on how to accomplish namespaced models would be helpful. I dont even need them namespaced on the client js side, as long as there is an easy way to specify the namespace for each individual model

like image 244
davydotcom Avatar asked Jan 14 '13 15:01

davydotcom


People also ask

What is store in Ember js?

The store contains all of the data for records loaded from the server. It is also responsible for creating instances of Model that wrap the individual data for a record, so that they can be bound to in your Handlebars templates.

Is Ember js a framework or library?

Ember. js is a JavaScript framework for creating ambitious web applications.


1 Answers

You should never have more than one store in an Ember application.

Instead, you can register adapters for specific types:

App.Store.registerAdapter('App.Post', DS.RESTAdapter.extend({
  // implement adapter; in this case
  url: "/gl"
}));

You will probably want to use the RESTAdapter as a starting point, unless you have specific needs and are willing to get down and dirty with the (still evolving) adapter API.

like image 63
Yehuda Katz Avatar answered Oct 31 '22 03:10

Yehuda Katz