Please tell me if this train of thinking makes sense, I need help on
solving this association model problem:
I am doing an app that creates and manages stereoscopic images, one
stereoscopic image is formed by two photos, say photo1 and photo2
The user uploads photo1 and then photo2 and gets a preview if he likes
the preview he/she authorizes it and gets a final stereoscopic image
All this images will be managed via file_column/RMagic plugins
When the user uploads photo1 and photo2 this are placed into an order,
(as when you place an order of fries…)
So there is an Order model that has_one of each:
Photo1 (high-res) belongs_to :order
Photo2 (high-res) belongs_to :order
Preview (low-res) belongs_to :order
Final (high-res) belongs_to :order
Each of Photo1, Photo2, Preview and Final models, need to have
additional user/server-information fields.
I am thinking of implementing this as a “Single Table Inheritance” with
self-referential join modeled like this:
create_table :stereos, :force => true do |t|
t.column :type, :string
common attributes
t.column :photo_name, :string
t.column :created_at, :datetime
t.column :updated_at, :datetime
t.column :order_id, :integer
attributes for type=Photo
t.column :date_taken, :datetime
t.column :pair_id, :integer
attributes for type=Preview
t.column :authorized_by_id, :integer
t.column :photo1_id, :integer
t.column :photo2_id, :integer
attributes for type=Final
t.column :photo1_id, :integer
t.column :photo2_id, :integer
end
Now for the hierarchy of model objects:
class Stereo < ActiveRecord::Base
end
class Photo < Stereo
end
class Preview < Stereo
end
class Final < Stereo
end
So the questions are:
1.- Is this a correct way to solve this relationships modeling problem,
will this work or is there a flow?
2.- photo1 and photo2 allways have to be associated in pairs, am i doing
this correctly via the pair_id field?
3.- preview is the product of merging photo1 and photo2 so i need to
make shure that each preview points to it’s parent via photo1_id and
photo2_id
4.- final is the product of merging photo1 and photo2 so i need to make
shure that each final points to it’s parent via photo1_id and photo2_id
5.- How should I manage field validations, where should I put them?