Polymorphic hasMany and BelongTo relationship


#1

I have a scenario where I need to create a polymorphic relationship that ties to a property that changes its name depending on the model.

let Story = DS.Model.extend(Imageable, {
  // Image is called cover
})

let User = DS.Model.extend(Imageable, {
  // Images are called images
})

let Imageable = Ember.Mixin.create({
  images: DS.hasMany('image', { inverse: 'parent' }),
  cover: DS.belongsTo('image', { inverse: 'parent' })
});

let Image = DS.Model.extend({
  parent: DS.belongsTo('imageable', { polymorphic: true })
})

If Imageable only needs to have image or cover, never both. However, I can obviously not say the inverse is ‘parent’ on both. Any thoughts on how to approach modeling such a relationship? Is such a relationship even possible with the current way ember-data handles polymorphic relationships?