Ember Data - hasMany / belongs with a different model than default
In Ember Data, how do you define a belongsTo / hasMany association that uses a different model or foreign key than the default one?
For example, I have App.Item
which belongs to models App.User
, but I want to access the user using an attribute owner
:
App.Item = DS.Model.extend({
owner: DS.belongsTo('App.User'),
});
item.get('owner'); // should be an App.User
// And the data from the server looks like:
{
owner: 2, //id
}
+3
source to share