First of all, based on existing models, you do not need to use polymorphic associations. And you may not want to set the polymorphic parameter at both ends of the relationship.
If you want your payload to contain listable , you just need to rename your attribute:
App.List = DS.Model.extend name: DS.attr('string') listable: DS.belongsTo('App.Project', { polymorphic: true })
UPDATE
Based on my understanding of your classes, this is a List that can belong to different types. Therefore, you should define your models as follows:
App.Listable = DS.Model.extend lists: DS.hasMany('App.List') App.Project = App.Listable.extend App.Proposal = App.Listable.extend App.Employee = App.Listable.extend App.List = DS.Model.extend name: DS.attr('string') listable: DS.belongsTo('App.Listable', { polymorphic: true })
and the payload will look like this:
{list: {name: "list1", listable_type: 'project', listable_id: 100}}
I do not know if you also want the list to be added to several lists at the same time. Based on the names of your models, I am inclined to believe that this is not what you want: the list should contain different objects (project, proposal, employee). not a project can have multiple lists.
Cyril fluck
source share