Reputation: 966
I'm implementing an app to manage prodution orders. Each order has many processes (stages), including printing and bending. All processes have some common attributes as quantity and comments, and some stage-specific ones:
create_table :stages do |t|
t.integer :number
t.decimal :roll_width
t.decimal :quantity
t.string :comments
t.boolean :finished
t.timestamps
end
create_table :printing_stages do |t|
t.integer :color
t.decimal :technical_card
t.timestamp
end
create_table :bending_stages do |t|
t.decimal :flap_width
t.boolean :seal_distance
t.timestamps
end
I'm not sure about the propper approach to follow here in order to be able to easily access their common + specific attributes.
If I use STI, I will end up with a HUGE sigle table since some stages have 10+ specific attributes.
If I use polymorphic associations as:
class Stage < ActiveRecord::Base
belongs_to :stageable, :polymorphic => true
end
class SlittingStage ActiveRecord::Base
has_one :stage, :as => stageable
end
class PrintingStage ActiveRecord::Base
has_one :stage, :as => stageable
end
then I would have to access for example a printing stage's comments such as printing_stage.stage.comments
, which is, IMHO, rather cumbersome and not so elegant as could be.
And finally, I'm not sure about the implications and consequences of using MTI.
Can you give me some advice?
Upvotes: 3
Views: 1176
Reputation: 3935
This lady says it better than I can. if you jump to around 20 minutes in that is where your answer lies.
Upvotes: 2