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
nicholaides
source
to share
1 answer
You can specify custom primary keys on the adapter. They must be installed prior to creating the repository.
App.Adapter.map('App.User', {
primaryKey: 'owner'
});
0
Cory loken
source
to share