Hi,
I have another conceptual question which is not really covered in the documentation. Or maybe it is just me not finding it or simply not understanding something.
The use case is actually exactly what we find covered in the getting-started tutorial: Ember Data - Part 2 - Ember Guides
Let’s keep the terms of this (very nice) tutorial. So we have a rentals homepage and want the user to be able to search for some specific places. This is solved in the tutorial by loading the data in the model hook:
async model() {
return this.store.findAll('rental');
}
and when the user enters something in the search bar, we sort all this rentals on the client side to display the ones where the keyword is matching some meta data of a rental .This “findAll” approach is very present throughout documentation and many examples.
This approach is ok for a tutorial, but imho it will not scale for a lot of real life use cases. Imagine we have 10000 rental entries in the database, we do not want to fetch all of them at first and then start looking for the 3 the user actually asked for on the client side. Instead we want only those 3 records to be fetched.
Now I do know how I can make this work in principle, I also digged around and found how the discourse software is doing it. If I am not mistaken they are firing the ajax call for the search in the controller:
And obviously it works. But being exposed to all this “load your data in the route, young padawan” mantra I am asking myself if… well … I can load the data in the model hook of the route somehow. Quite some time has passed since discourse was written and so maybe there is some other way which is more in line with “the ember way”.
The problem of course is that the model hook already fired when the user gets the chance to type anything into the search box. At least when we look at the way it is done in the getting-started tutorial. So we can not add the keyword the user typed into the store search query.
Is there something in the documentation I am missing that covers this aspect? In this case a link would be much appreciated.
If not, can someone with more ember experience explain how this can be done using ember-data and the model hook? Somehow with nested routes which we can call again when the user finished typing (without rerendering the whole page/parent template)? Ideally it would use query parameters, so users could bookmark search results. Here I am not sure how I am supposed to put the query-parameters in the store query in a sane way.
I feel like ember could benefit from a refined+documented way to do this kind of stuff (… if this is not already covered in the documentation of course).
Thanks!