Objects that are not stored on the server

Here’s and object that has predefined properties in order to store some values throughout the lifetime of the app but not to be stored in the database.

For example I need to store an object that defines certain filter attributes. Like so:

App.Filter = Ember.Object.extend({
  label: null,
  value: null,
  prop: null

Where does an object like that belong within the Ember structure. According to Ember’s definition of Model it is an object that is persisted on the server. My example in only created on the client at run time.

Please note that I also have a ArrayController that manages a list of all available Filters and currently selected filters.

In cases like this I always tend to create an additional controller for such a model. You can setup the controller along with the model of your ArrayController and then inject the controller into the array controller using needs.


App.FilterController = Em.ObjectController.extend();

App.PostsRoute = Em.Route.extend({
  model: function () {
    // get your posts
   setupController: function () {
     var myCoolFilter = App.Filter.create();
     this.controllerFor('filter').set('model', myCoolFilter);  

App.PostsController = Em.ArrayController.extend({
  needs: ['filter'],
  filter: Em.computed.alias('controllers.filter')
1 Like