Given assessments and messages sent by a member, I'd like to find all the logs associated to a member with a specific email. I am running into issues joining polymorphic associations EagerLoadPolymorphicError Cannot eagerly load the polymorphic association
. I assume I should join Log with the consumer association and then add a conditional for the members email.
I am using Rails 6.0.3.7
My models are the following:
class Assessment
belongs_to :member, foreign_key: 'sender_id'
has_one :log, as: :consumer
end
class Message
belongs_to :member, foreign_key: 'sender_id'
has_one :log, as: :consumer
end
class Log
belongs_to :consumer, polymorphic: true
end
class Member
has_many :assessments
has_many :messages
end
I have tried various forms of the following:
Log.joins(consumer: :member).where(members: {email: 'john@cheese.com'})
#ActiveRecord::EagerLoadPolymorphicError (Cannot eagerly load the polymorphic association :consumer)
I then thought perhaps I could do a belongs_to :through but apparently that's no good either belongs_to through associations. Is what I am trying to do even possible?