I am needing to create a gallery containing entries from two different models/tables, let's say "video" and "image". What is the best way to handle this? I would like to keep them in different tables, but retrieve them together (the most recent 50 images and videos, for example). Single Table Inheritance doesn't seem to fit. Any ideas?
2 Answers
The best way I have been able to figure is to have a table of all the displays with polymorphic references to the other tables.
class Gallery
has_many :displays
end
class Display
belongs_to :gallery
belongs_to :derived_display, :polymorphic => true
end
class Video
has_one :display, :as => :derived_display
end