mercredi 4 novembre 2015

Updating a specific record in Ember Data without making HTTP calls?

I have an Ember.js model called emails. This is what the file looks like:

import DS from 'ember-data';

export default DS.Model.extend({
    label   : DS.attr('string'),
    primary : DS.attr('string'),
    email   : DS.attr('string')
});

I am fetching results from the server and pushing data in by doing something like:

this.store.createRecord('emails', {
    label: 'Foo',
    primary: true,
    email: foo@bar.com
});

I have a form that allows users to add new emails to the store. Once they add a new one, I am pushing it to the store using the above code.

There can only be one record in the store with the key primary' set totrue`. When a user adds a new primary email, I need to manually edit any existing primary email to false and only then add the new email record.

I tried doing something like this.store.peekAll('emails') and parsing it but I can't seem to understand how to fetch only the record where primary: true and update it. How can I accomplish this?

Remember, I am not using the REST Adapter so I cannot query Ember Data like this: http://ift.tt/1MyZCgO.




Aucun commentaire:

Enregistrer un commentaire