Reputation: 615
Is there a way to specify the name of the other side of a relationship in ember js.
Like you can specify the class_name and foreign_key args to a relationship in rails.
Edit
Just to clarify, here are my models:
App.Menu = DS.Model.extend
menu_pages: DS.hasMany 'App.MenuPage'
embedded_menu_pages: DS.hasMany 'App.MenuPage'
App.MenuPage = DS.Model.extend
menu: DS.belongsTo 'App.Menu'
embedded_menu: DS.belongsTo 'App.Menu'
The problem is when i set embedded_menu on a MenuPage instance. Ember is then adding an item to the menu_pages array in the Menu model, rather than adding an item to the embedded_menu_pages array.
Upvotes: 0
Views: 835
Reputation: 12011
Looking at the tests in https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/inverse_relationships_test.js#L45
You should be able to define the inverse part relations when they are ambiguous. In your case something like
App.Menu = DS.Model.extend
menu_pages: DS.hasMany('App.MenuPage'), inverse: 'menu'
embedded_menu_pages: DS.hasMany 'App.MenuPage', inverse: 'embedded_menu'
App.MenuPage = DS.Model.extend
menu: DS.belongsTo 'App.Menu', inverse: 'menu_pages'
embedded_menu: DS.belongsTo 'App.Menu', inverse: 'embedded_menu_pages'
(My apologizes if the syntax does not fit with coffescript)
Upvotes: 2