EmberJS: How to specify a specific model url in ember-data RESTAdapter?

Question 1: If I have an ember-data data model called Company, how can I tell it to hit /businesses and /businesses/:id to retrieve records? Is there a way to specify a URL for this model? Even better, like BackboneJS, can I calculate the model url at runtime?

Questions 2: I have a somewhat unique requirement, my API is organized like this:

/api/v1/company/:company_id/form/:form_id/items/:item_id

Is there any way to handle this with EmberJS? I understand that ember has a relationship like DS.hasMany ('App.Items'), but it seems to get into the URL /items/:item_id to get the data instead of the full URL.

How do I solve this problem?

+4
source share
1 answer

Answering your first question, when you create your store, you can do this:

 DS.RESTAdapter.configure("plurals", { company: "businesses" }); 

Regarding your second question, based on these guides , I believe that you can use a namespace like the following by replacing identifiers with your company, but I have not done this before, so I canโ€™t say for sure that this will work. Assuming that you land in your application, knowing these identifiers, you can technically replace them:

 DS.RESTAdapter.reopen({ namespace: '/api/v1/company/<replace>/form/<replace>' }) 

You can also try installing the url model.

You can learn more about it here.

+2
source

All Articles