Rails 3: Should I use STI or just an extra column? (search for advice)

I am working on a project (Rails 3.0.3), where, I think, I may need to use STI, but I'm not sure what I should just add an additional column to the table and do with it.

In my object model (for the game system) I have players (who belong to agencies) and owners (owning agencies).

Both players and owners belong to agents who are the user account, so the agent can be a player and / or owner in many agencies.

Instead, I would have to call the "user" user agent, oops. So I have this:

class Agency < ActiveRecord::Base
  has_many :players, :class_name => "Player", :foreign_key => "agency_id"
  has_many :agents, :through => :players, :source => :agent_id
  has_one :owner, :class_name => "Owner", :foreign_key => "agency_id"
end

class Player < ActiveRecord::Base
  belongs_to :agency, :class_name => "Agency", :foreign_key => "agency_id"
  belongs_to :agent, :class_name => "Agent", :foreign_key => "agent_id"
end

class Owner < ActiveRecord::Base
  belongs_to :agency, :class_name => "Agency", :foreign_key => "agency_id"
  belongs_to :agent, :class_name => "Agent", :foreign_key => "agent_id"
end

, , , ( , , ).

, , .

, (, - undefined, - ), , .

, STI , , , .

, boolean/tinyint Player, is_owner, , .

, - , , - - ?

+3
1

, Player Owner Agent Agency. , Agent Agency Agent Agency. , , , Role, Player Owner. : - Role? , , ?

, . , ( ) mixin (s) .

. -, , . - . , . .

, is_a, shares_some_code_with . : , . .

+1

All Articles