What's the equivalent of
App.Person.filter(function(e){return e.get('age') == 30})
in the new Ember Data?
In the old Ember Data, App.Model.filter
produced a different type of object versus App.Model.find
(see this question). I discovered the type difference because if I wanted the record itself and make changes, I had to use filter
. So find
was kind of like read-only. (Correct me if I'm wrong.)
Is it the case in the new Ember Data?
Polymorphism. Polymorphism is a powerful concept which allows a developer to abstract common functionality into a base class. Consider the following example: a user with multiple payment methods. They could have a linked PayPal account, and a couple credit cards on file.
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.
Class Store 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. Define your application's store like this: app/services/store.js.
A Service is an Ember object that lives for the duration of the application, and can be made available in different parts of your application. Services are useful for features that require shared state or persistent connections. Example uses of services might include: User/session authentication. Geolocation.
In the new Ember Data (Beta 1.0.0) you can use the filter
function from the DS.Store
class. Unlike the previous filter
function of the Model, you have to specify the type of Model you want:
this.get('store').filter('person', function(record){return record.get('age') == 30});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With