chopper
chopper

Reputation: 6709

Custom Model URL

Is there currently (in the latest builds) a way of specifying a URL on a model-by-model basis? in Ember Data 1.0 beta? I have found some questions on SO and issues on Github around this, but most are out-dated.

For example, I have a model that's called App.PaymentSearchResult and rather than having the request go to /payment_search_results I would like it to go to /payments/search. Where would I override the URL used for a given model (rather than overriding buildURL on the RESTAdapter)?

Upvotes: 0

Views: 79

Answers (1)

MartinElvar
MartinElvar

Reputation: 5804

You can override the the find adapter but it's kind of hackish, i think however i would take another approach. Idealy you want your Ember models to reflect your backend's models, so why would you need a PaymentSearchResult? When you probably already have a Payment model?

If you need to search in your payment records, why not handle it using query params? http://emberjs.com/guides/models/finding-records/#toc_querying-for-records

this.store.find('payment', { total: "22" });

Then you want to answer accordingly on the server.

If you want to do a search which returns multiple models, you do this with a manual ajax request.

var self = this;
$.get( "/search", { name: "John", time: "2pm" }, function(result) {
   self.store.pushMany(result);
});

PushMany assumes a sane JSON structure. http://emberjs.com/api/data/classes/DS.Store.html#method_pushMany

Upvotes: 1

Related Questions