I have no findRecord in the route, but Ember still find the record

Hi:

I have a CRUD to experiment and test things with my backend, and I have noticed something strange with this two nested routes:

  • clients/index hits the back end
  • clientes/show/:id do not (when following a link)

Maybe this happens because the only source of truth is the model already loaded in index. Is that true? If I reload the show page it does hit the backend.

I don’t like this behaviour too much, but now I have just discovered that in the show route… I have nothing!!

Is Ember Data magically creating the “return this.store.findRecord” action?

What I want now is to improve the call to manage errors with promises, but I don’t know where is that call to the back end.

I am a little bit lost with this magic :slight_smile:

Nacho B.

Hey Nacho,

Posting your app/router.js file would help finding out what exactly is going on, but here are a few things that are true in general:

  • If you don’t specify a model hook for a route, the route will inherit its model from its parent route. So if you have band.details nested under band and you don’t specify a model hook for band.details, it will be that of band.
  • this.store.findRecord immediately (=not blocking rendering) returns the record if it’s already in the store and it’ll then fetch that record in the background from the back-end to keep it fresh.
  • this.store.findAll immediately (=not blocking rendering) returns all the records of that type if there are any in the store and it’ll re-fetch them in the background from the back-end to keep it fresh.
  • The last two behavior can be adjusted with adapter configuration.

These two presentations I gave might also help:

And possibly, my book, too: The most up-to-date book to learn Ember Octane

Thank you!

I see. My clients/show route has no model hook, so it inherits the model from its parent.

I also have found that to force the reload, apart from editing the adapter I can just include the id in the link:

{{#link-to “clients.show” party.id}}

Not used to this behaviour, but I really like the possibilites of customization. Some models do not need to be reloaded.

Regards: Nacho B.

Right, I agree.

Great, you have found the useful “hack” of Ember developers. Not firing the model hook when the model is passed into link-to is considered more like a bug than a feature and might soon change.