Polymorphic associations without inheritance


#1

Hi,

I use Ember Data with ActiveModelAdapter.

In my rails backend I have this polymorphic association:

class Schedule < ActiveRecord::Base
  has_many :schedule_ranges, as: :schedule
end

class ScheduleTemplate < ActiveRecord::Base
  has_many :schedule_ranges, as: :schedule
end

class ScheduleRange < ActiveRecord::Base
  belongs_to :schedule, polymorphic: true
end

It results that the association ‘schedule’ in ‘ScheduleRange’ has the same name than the polymorphic model ‘Schedule’.

In ember-data it’s not possible to use inheritance to define polymorphic association because the parent and the child would have the same name.

I can’t find a solution tu use my backend with ember-data. Can you help me?


#2

I haven’t tried this myself but I bumped into this the other day whilst looking on stack over flow.


#3

There is also this:

Polymorphic associations tutorial

But this is justly this implementation that doesn’t allow to use my naming case.