Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get store name of Ember Data model

How can I determine the "store name" (not sure what the proper terminology is) for a given ED Model? Say I have App.Payment, is there a store method that let's me look up its corresponding name, i.e. payment (for example to use in find queries)?

like image 734
chopper Avatar asked Nov 21 '13 09:11

chopper


People also ask

What is store in Ember?

One way to think about the store is as a cache of all of the records that have been loaded by your application. If a route or a controller in your app asks for a record, the store can return it immediately if it is in the cache.

What is a model in Ember?

In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.

What is an ember controller?

In Ember. js, controllers allow you to decorate your models with display logic. In general, your models will have properties that are saved to the server, while controllers will have properties that your app does not need to save to the server.


1 Answers

For Ember Data 1.0 (and later)

modelName is a dasherized string. It stored as a class property, so if you have an instance of a model:

var model = SuperUser.create();
console.log(model.constructor.modelName); // 'super-user'

For Ember Data Pre 1.0

typeKey is the string name of the model. It gets stored as a class property of the model, so if you have an instance of a model:

var model = App.Name.create({});
console.log(model.constructor.typeKey); // 'name'
like image 75
typeoneerror Avatar answered Sep 20 '22 15:09

typeoneerror