Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do filter in the new Ember Data? Also how does filter compare to find in the new Ember Data

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?

like image 304
HaoQi Li Avatar asked Sep 12 '13 05:09

HaoQi Li


People also ask

What are polymorphic models in Ember?

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.

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 store in Ember?

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.

What is service in Ember?

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.


1 Answers

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});
like image 129
Simon Cateau Avatar answered Sep 22 '22 13:09

Simon Cateau