mardi 24 mai 2016

Stop emberjs to send request to server for loaded record

I am having a customer model and a product model

customer model

import DS from 'ember-data';
export default DS.Model.extend({
    type: DS.attr('string'),
    name: DS.attr('string'),
    product: DS.hasMany('product')
});

product model

import DS from 'ember-data';
export default DS.Model.extend({
    type: DS.attr('string'),
    name: DS.attr('string'),
    customer: DS.belongsTo('customer')
});

I load all the customer in model() hook of route.js as below

model() {
    customers: this.store.findAll('customer'),
}

so as of now I have all the records of customer.

then using findRecord method I load perticular product as

this.store.findRecord('product', productId);

now when I write in template as



it send a get request to load the customer which is already loaded. I want to stop that request how I can do this ?

As per my knowledge

When we already have the record, store.findRecord will resolve immediately with cached data, but will send a request in the background to update the record and once the record is updated your template will show the new changes.

I want to stop that request.




Aucun commentaire:

Enregistrer un commentaire