Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Ember data stop changing my endpoints to singular and plural according to its rules?

I need Ember to stop trying to guess things when making calls to the REST endpoints, but can't find a way do do so.

If I have an endpoint say, /services, I want ember to always call /services regardless if I'm making a call to find('services') or find('services', 1)

Same for singulars.

Is it possible to disable this behavior? Even if I have to override methods in the REStAdapter that'd be OK.

Thanks!

like image 265
Edy Bourne Avatar asked May 31 '14 21:05

Edy Bourne


People also ask

What is adapter in Ember?

In Ember Data, an Adapter determines how data is persisted to a backend data store. Things such as the backend host, URL format and headers used to talk to a REST API can all be configured in an adapter. Ember Data's default Adapter has some built-in assumptions about how a REST API should look.

What is store in Ember?

One way to think about the store is as a cache of all of the records that have been loaded by your application. If a route or a controller in your app asks for a record, the store can return it immediately if it is in the cache.

What is model in Ember?

In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.


1 Answers

Sure, but you still should use find('service').

Plural (this is the default implementation)

App.ServiceAdapter = DS.RESTAdapter.extend({
  pathForType: function(type) {
    var camelized = Ember.String.camelize(type);
    return Ember.String.pluralize(camelized);
  },
});

Singular

App.ServiceAdapter = DS.RESTAdapter.extend({
  pathForType: function(type) {
    var camelized = Ember.String.camelize(type);
    return camelized; //Ember.String.pluralize(camelized);
  },
});

Base Singular Class

App.BaseSingularAdapter = DS.RESTAdapter.extend({
  pathForType: function(type) {
    var camelized = Ember.String.camelize(type);
    return camelized; //Ember.String.pluralize(camelized);
  },
});

Both Foo and Bar would be singular using the code below

App.FooAdapter = App.BaseSingularAdapter;

App.BarAdapter = App.BaseSingularAdapter;
like image 72
Kingpin2k Avatar answered Oct 23 '22 01:10

Kingpin2k