How to prevent Ember-data from making a request to the server

Asked

Viewed 33 times

0

I have a route where the person can select items from a list for their account. But logging into that route sends a request GET to the server. How could prevent this from happening?

Here is an excerpt from the code. I am using Emberjs 2x

import Ember from 'ember';

export default Ember.Route.extend({
    searchPlaces: Ember.inject.service(),
    model() {
        return this.store.findAll('user');
    },
    afterModel(model) {
        let token = model.get('token');
        let places = model.get('places');

        this.set('places', places);
        this.set('token', token);
    }
});

1 answer

0

According to that reply from SOEN

The problem is using the findAll instead of peekRecord or peekAll. When reading the documentation on DS.store we can find the following cases.

  • findRecord - resume a promise, first query in memory and then on the server if it is not found.
  • findAll - It looks like the findRecord, but consults all.
  • peekRecord - returns the result of the item that is already in memory, or null if not found; does not query the server.
  • Relate the item - returns an Array with the results found and already in memory.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.