Single Table Inheritance with self-referential join

A stereo image is two almost identical images (one slightly offset)
placed side-by-side such that when viewed properly will produce a 3D
effect. Therefore you might be better off with this hierarchy because
Photo, Preview, and Final are all Images regardless of their source.
Then have a separate Stereo class be the parent relating the 3-types of
images.

class Image < ActiveRecord::Base
  belongs_to :stereo

class Photo < Image

class Preview < Image

class Final < Image

class Stereo < ActiveRecord::Base
  has_many :images

create_table :images, :force => true do |t|

t.column :type, :string

# magic attributes
t.column :type :string # required to activate STI
t.column :created_at, :datetime

# common attributes
t.column :stereo_id :integer # the parent
t.column :path :string # file has to be somewhere
t.column :photo_name, :string

# attributes for type=Photo
t.column :date_taken, :datetime # irrelevant to the task?
t.column :is_left :boolean #

# attributes for type=Preview

# attributes for type=Final
end

create_table :stereos, :force => true do |t|

# magic attributes
t.column :created_at, :datetime
t.column :updated_at, :datetime

# common attributes
t.column :order_id, :integer # An Order has many Stereos

# a user actually authorizes a stereo to be finalized
t.column :authorized_by_id, :integer

end

Don't forget you have to define each class in it's own model file for
it to work. Also take my advice with a grain of salt as I've only been
at this for a week and only found out about STI 2 days ago. :slight_smile: