I need to access an information that is stored 2 relations from the one I'm doing the query on.
class Information < ActiveRecord::Base
...
belongs_to :information_type, polymorphic: true
...
end
class InformationTypeOne < ActiveRecord::Base
...
belongs_to :location
has_one :information, as: :information_type
...
end
class InformationTypeTwo < ActiveRecord::Base
...
belongs_to :location
has_one :information, as: :information_type
...
end
class Location < ActiveRecord::Base
has_many :information_type_ones
has_many :information_type_twos
end
So what I would like to to do is to find all information belonging to one location, no matter what InformationType it is.
Best case would be something like Information.where(location: 'Location A')
Anyone knows how to realize this?
--- UPDATE ---
I managed to at least get the location belonging to an information by addings this:
delegate :location, to: :information_type
If I now could somehow make this work:
Information.where(location: 1)
I would be very happy. Anyone? :)