Multiple inheritance of Rails and activerecord tables

I am trying to implement multiple table inheritance using ActiveRecord. It looks like all the gems available are pretty old. Am I missing something? Is there a "native" way to implement this with activerecord? I am using Rails 3.2.3 and activerecord 3.2.1

+4
source share
1 answer

Inheritance of separate tables (where each car and truck have one database)

class Vehicle < ActiveRecord end class Car < Vehicle end class Truck < Vehicle end 

In your case, you are not using a database, but rather functions. Then you have to write a module and include it in each model

 class Car < ActiveRecord extend VehicleFinders end class Truck < ActiveRecord extend VehicleFinders end module VehicleFinders def find_purchased #... end end 

Thus, in the extend module, the class method is the class method for this calling class. include module methods - this is an instance method for the object of the calling class

It may be useful to read for you http://raysrashmi.com/2012/05/05/enhance-rails-models

+1
source

All Articles