Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - What is the design pattern to subclass a model?

I have a model:

class Item < ActiveRecord::Base

Item has a property 'store'

Based on the value of store, I'd like the Item object to have different behaviour for specific methods.

Is there a common design pattern for this in Rails? How is this done cleanly without a big if-else statement in the methods?

like image 863
NatGordon Avatar asked Mar 10 '11 22:03

NatGordon


1 Answers

Usually through Single-Table Inheritance.

like image 110
Jakub Hampl Avatar answered Oct 05 '22 23:10

Jakub Hampl