Search code examples
ember.jsember-dataember-cli

EmberJS client side record management (ember-data)


I have just started trying to use ember-data. I have an ember app for which I need to produce all the data on the client side and then save it all at once. So my object graph has a "Project" as the root object, then a project can have many "Sections" and then each section can have many "Items".

I am up to the stage where I am trying to create Item records on the client side and add them to the correct Section. When I am ready to save the data I just want to use project.save() and have it go and save the object graph instead of saving every time the model changes.

I am trying to look up the section to place the items in by name using store.filter({name:"section1"}) but ember keeps trying to go to the server to look them up. I see this in the console: GET http://localhost:4200/sections?name=Section1 404 (Not Found).

This is what I am trying to do:

store.filter('section', {name:'Section1'}, function(section) {
        return section;
      }).then(function(section)
        {
          var record;
          //create a record
            section.pushObject(record);
        });

Solution

  • You are doing server side filtering and you want client side filtering.

    Please read this article carefully.

    In short, you should do

    store.filter('section', function(section) {
      return section.get('name') == 'Section1';
    });