Answer the question
In order to leave comments, you need to log in
How to write a joins query in rails for polymorphic links?
There are models
class Entry< ActiveRecord::Base
belongs_to :record, polymorphic: true
end
class EntrySpecial< ActiveRecord::Base
has_one :entry, as: :record
end
Answer the question
In order to leave comments, you need to log in
solved the problem a bit
class Entry< ActiveRecord::Base
belongs_to :record, polymorphic: true
belongs_to :entry_special, foregin_key: 'record_id'
end
I recommend using gem squeel. It's
done like this: Entry.joins { record(EntrySpecial) }
And then you can include selection conditions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question