Rails - Polymorphic Association or Single Column Inheritance

I am torn between STI, polymorphic association or type table. I already have a unit table with the following fields:

name
account_id
speed_limit
is_speeding
activation_state
unit_status_id

In fact, there are three different types of units: gps units, oil units, and refrigerator units. When a user logs in, their web page conditionally changes depending on which device it is. All three of these objects have an account, activation_state and unit_status_id, among other fields. But only the gps block has a speeding_limit or is_speeding field.

Should I use polymorphic association:

class Unit
  belongs_to :unitable, :polymorphic => true 
end

class RefrigeratorUnit < ActiveRecord::Base
  has_one :units, as: => :unitable
end

class OilUnit < ActiveRecord::Base
  has_one :units, as: => :unitable
end

class GpsUnit < ActiveRecord::Base
  has_one :units, as: => :unitable
end

Or should single-page inheritance be used?

class Unit < ActiveRecord::Base
end

class GpsUnit < Unit
end

class RefrigeratorUnit < Unit
end

class OilUnit < Unit
end

STI, , , . , , gps, . , has_one, , , gps-, , . . .

+4
1

, - , , , - GpsUnit, OilUnit, FridgeUnit.

- , :

 belongs_to :unit, :polymorphic => true

, , STI - , .

+2

All Articles