I’m wondering if I need to extend the DS.Store class in order to add a query method like this.store.search() for example, would it be possible on the current version?
This need comes from the fact that I have a JSONAPIAdapter-like backend API but with some minor changes. For example I have a custom route to perform searches on the model /{model}/search and none of the existing methods, findAll(), query() and others help me achieve this functionality without overriding some of them which is not something I really like.
The build-in this.store.query() method works great if I want to query on a specific model field, but for search() I’m using a text parameter which looks over multiple model fields to find a match.
The best approach in my opinion would be to extend the DS.Store class and add a this.store.search() method for example that would allow me to automatically search for records on any model.
Sorry, but I don’t get why query() does not work for you? I am using query() for all of my requests to a paged API, even for sort and filtering. All you have to to is to add some queryParams to you route…
As for non-standard URLs: You can tweak the URL either in the adapter or you are free to do things like that to circumvent the adapter and ORM completely:
actions: {
// this cancels the subscription by issuing a non-standard ajax call
cancel: function(param) {
Ember.Logger.info("Huh?");
// get token and add it to the request header of our ajax call
this.get('session').authorize('authorizer:custom', (headerName, headerValue) => {
const headers = {};
headers[headerName] = headerValue;
Ember.$.ajax({
url: "http://******/v1/subscriptions/" + param + "/cancel/",
type: "POST",
data: null,
headers
}).then(
this.onSuccessfulCancel.bind(this),
this.onFailedCancel.bind(this)
);
});
},
},
As I mentioned in the OP, the endpoint responsible for search uses another url schema, query() will make a request to /{model} while I had to fetch /{model}/search and also pass some other parameters. Anyway, I have made the changes from the API server and created a separate search model in order to be able to fetch it the other way, like /search/{model}