rails polymorphic with includes different association based on type of class

32 views Asked by At

my question is how to include different association depend on class type when polymophic. below is example.

class History
  belongs_to :history_able, polymorphic: true
end

class ReviewHistory
  has_many :histories, as: :history_able
  has_many :reviews
end

class InterviewHistory
  has_many :histories, as: :history_able
  has_many :interviews
end

class Review
  belongs_to :review_history
end

class Interview
  belongs_to :interview_history
end

I want to eager load different model based on history_type. for example, when History is ReviewHistory type, then include reviews, when History is InterviewHistory then include interviews.

please let me know if there is good tip for this situation.

0

There are 0 answers