ruby on rails - Should I use STI or polymorphic model? -


i have 2 models futuremap , milestone

futuremap

class futuremap < activerecord::base   attr_accessible :name   has_many :milestones end 

milestone

class milestone < activerecord::base   attr_accessible :description, :type   belongs_to :futuremap end 

the different types of milestones, work, highschool, college , right telling them different attribute type. not great design.

this because find out need store information when type work , less when college.

should make subclass of different types or make milestone polymorphic model? how can make better design, suggest or ideas welcome.

single table inheritance (sti) great sort of thing if there's fair amount of commonality between various milestones. in age of terabyte-sized hard drives, wouldn't worry not utilizing of fields of time. having simpler schema trumps minor space saving you'd achieve @ expense of complexity.

there's no such thing "polymorphic model", there polymorphic relationships between models. these lot more difficult database understand, require compound key , cannot validated using foreign key constraints, can useful in specific circumstances.

this situation you're describing, however, not 1 of those.

polymorphic relationships best left "edge" of entity relationships overhead of retrieving them can higher. ideally should never involved in :through relationship, or join might involved, complexity of query escalate.

sti tables regular records far database concerned. type column hint orm how instantiate it. on whole they're quite efficient long entities have fair amount of commonality.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -