Mattew
Mattew

Reputation: 537

Find Methods in derived classes with ActiveRecord - Single Table Inheritance

I have a class that derives from ActiveRecord::Base. This class has a subclass that is differentiated in the database by a type id column. How do I make sure that all the inherited active record functions in the derived classes append the type_id column to the conditions hash on any queries that are executed by the derived class? Are there any kind of "before" functions that I could override to inject a condition into the process for the derived classes?

Thanks!

Upvotes: 0

Views: 735

Answers (2)

srboisvert
srboisvert

Reputation: 12749

What you are doing is called Single Table Inheritance (STI). That's why what Radar said about your column being called type works.

Upvotes: 1

Ryan Bigg
Ryan Bigg

Reputation: 107728

If your column was called "type", ActiveRecord would do this automatically for you.

Upvotes: 3

Related Questions