mercredi 9 décembre 2015

can't get store.findAll to work

I have a fairly simple ember-cli application (using Ember 2.2 & Ember Data 2.2.1) with a single model named 'scenario'. I have a route name 'scenarios' that lists all the scenarios. All that works fine. In my application template, I have a nav bar with a button that triggers an action to delete all scenarios. My application controller code looks like this for that action:

this.store.findAll('scenario').then(function(recs){
    recs.forEach (function (rec) {
        rec.destroyRecord();
        });
    }, console.log ('findAll Scenario failed'));

When I run this code, the console.log always prints, indicating that the promise returned didn't fulfill. But there are clearly records in the scenario model. I can see them on the screen in the "scenarios" route, and also in Ember inspector. Why is this 'findAll' not fulfilling?

One other thing to note: when this code is run, Ember Inspector actually shows the same records I'm trying to delete been added. (e.g., if I have 2 scenarios with ids 23 & 24 respectively, initially I see two rows in Ember Inspector as expected. After this code runs, I see 4 rows, two with id 23 and two with id 24). But the 'MODEL TYPES" column in Ember inspector still says scenario(2), indicating only 2 records. Anyone know what's going on?




Aucun commentaire:

Enregistrer un commentaire