How to change default findAll url


#1

I’m doing a app that have several users, and each user hasMany mappings.

So, i’m not using JSONAPAdapter because i’m working with strongloop, so i’m using RESTAdapter with JSONSerializer.

All my mappings routes in the backend work like this:

GET        /users/{userId}/mappings
POST     /users/{userId}/mappings
PUT       /users/{userId}/mappings
DELETE /users/{userId}/mappings
GET        /users/{userId}/mappings/{mappingId}
.....

So, i want get all mappings from the logged user. How to do so? I’m trying like this:

this.store.query('mapping', {
   userId: userId
});

But doesn’t work at all. Is trying to get the data from /mappings/{userId}

Is it possible to overwrite the default findAll url? How so?

Thanks!


#2

You can create an adapter for mapping and override urlFor.. methods. Then use like this.store.adapterFor('mapping'). ...


#3

Correct on the first sentence. But you shouldn’t need to call the adapter manually. Instead, just do a this store.findAll(‘mapping’) and let the store pick the mapping adapter automatically


#4

Yes. The point is overriding adapter urlFor... methods


#5

@acorncom @jmimi isn’t working. That’s how i’m trying:

export default ApplicationAdapter.extend({
  urlForFindAll(id, modelName, snapshot) {
    console.log(
      'test'
    );
  }
});

#6

For which adapter you override? mapping or user


#7

@jmimi mapping!!!


#8

mapping is a model you are using


#9

Lol, that’s some prime example of Ember support and community right there.

Community problems aside it is ridiculous how unbelievably bad Ember documentation is, there is literally none doc whatsoever on the issue. Each time I have to do something really simple, something that would take 10 minutes in React or Angular, I have to spend hours digging through the support topics, stackoverflow, and Ember docs.

To the pity souls that are still stuck with Ember — hang on there guys!


#10

Here is the answer to original question it is actually present in API docs, though no info in the guides: http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_urlForQuery


#11

If you have questions or something isn’t clear in the docs, just ask. We iterate on them with every release.