Sideload models by ID rather than all at once


#1

When my route loads, I’m grabbing an account from the server which hits this API endpoint:

/api/1/accounts/10001262/

and returns this:

{
    username: "HallOatesFan",
    interactions: [
        "e0ac813142e56cf35c587232438e0677",
        "twitter-tweet-403630764916363265-10001262",
    ]
}

When Ember sees the interactions array, it makes a request to this endpoint to retrieve the complete models:

/api/1/accounts/10001262/interactions/

and returns this:

[
    {
        name: "andy matthews",
        native_id: 123456789
    },
    {
        name: "andy matthews",
        native_id: 987654321
    }
]

The interactions endpoint calls a CouchDB design doc which could potentially be out of date when the request is made. We have a seperate endpoint which Ember already knows about that loads the specific CouchDB document directly. We’d like to get Ember to make a request to the Interaction by ID endpoint instead of the Interactions by account to load each interaction.

/api/1//interactions/twitter-tweet-403630764916363265-10001262/

Is this possible? If so, how would we accomplish it?

The setup

Ember: 1.3.0-beta.1+canary.ea261c9f
Ember Data: 1.0.0-beta.2
Handlebars: 1.0.0
jQuery: 2.0.3 

Social.Account = DS.Model.extend({
    username: DS.attr("string"),
    interactions: DS.hasMany("interaction"),
});

Social.Interaction = DS.Model.extend({
    native_id: DS.attr("string"),
    name: DS.attr("string"),
    account: DS.belongsTo("account"),
});