Is it possible to have query params work with an object? And if not, is there a better way to go about supporting this without enumerating each value and then manually creating a filter param?
Never found an answer. Ended up bailing on JSON API at the time, b/c it wasn’t baked in to Ember enough. Not sure if it’s any better now. I ended up using the RESTSerializer instead.
Hi all! Hope you don’t mind me reviving such an old thread, but I’ve been working on the same issue myself, and I was able to get it working, so thought I’d share:
All you have to do is use square brackets when you define your filter:
filter: [],
If you then set the value of filter as an object, for instance:
Hi I am new to Ember. Rather to answer the question, I am confused why you would need queryParams in Controller since you already defined it in Route. Can someone explain what’s the difference between queryParam in Route vs Controller? Thanks
Basically, the Controller and Route perform different functions in Ember. The Route determines which templates to render, which model to load, and handles redirecting to new routes based on the state of the URL. The Controller extends the model for a given route, and is a place to put additional route-based data and actions.
Query Parameters in Ember are bound to the Controller, so the Controller is where you declare query parameters and where you go to change the values of parameters. Generally speaking, all of the code related to query parameters can go in the Controller, and any time a parameter is updated, it will fire hooks in the controller it is associated with.
However, in a few situations, you may need a query parameter to be able to fire Route-based hooks instead—the most common situation for this is if you need to re-load the route’s model based on changes to a specific query parameter. When dealing with this sort of case, you need to add a declaration to the route associated with your controller that tells it to fire the extra hooks.
So basically, query parameters are defined in the Controller, but need to be referenced in the Route if there is a Route action that depends on changes to your query parameters.