Stargazer
Stargazer

Reputation: 542

Ember Resource URL: how to make it use other values rather than ID?

I need to make a Ember Resource to send its query using one of values in its schema.

Let's say I've defined this resource:

App.SomeModule = Ember.Resource.define(
{
    url: './api/some',
    schema:
    {
        id: Number,
        fodder: Number,
        whatever: Number,
        units:
        {
            type: Ember.ResourceCollection,
            itemType: 'App.OtherModule',
            url: './api/other/%@'
        }
    }
});

When this resource need to load its 'units', it will automatically send a query using the url "api/other/(id). However I need to make it use other value such as (fodder) or (whatever), not id. I think (%@) need to be replaced but how?

Upvotes: 2

Views: 917

Answers (1)

Josh
Josh

Reputation: 68

You probably want to define url as a function instead:

units: {
  url: function() {
    // your custom code here:
    return '/api/other/%@'.fmt(this.get('fodder'));
  }
}

Upvotes: 2

Related Questions