I have a ploymorphic association named Notifiable in a model named Notifiaction :
module Notifiable def self.included(base) base.instance_eval do has_many :notifications, :as => :notifiable, :inverse_of => :notifiable, :dependent => :destroy end end end class Bill < ActiveRecord::Base include Notifiable end class Balance < ActiveRecord::Base include Notifiable end class Notification belongs_to :notifiable, :polymorphic => true belongs_to :bill, foreign_key: 'notifiable_id', conditions: "notifiable_type = 'Bill'" belongs_to :balance, foreign_key: 'notifiable_id', conditions: "notifiable_type = 'Balance'" end
when I try to join a notification with a notification ( Notification.joins{notifiable} is squeel, the active recording code will have the same result) I get an error: ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :notifiable
I saw several posts about this exception, but none of them was exactly my case when I try to just join tables. Is it possible? what am i missing
join ruby-on-rails activerecord polymorphic-associations
benams
source share