Something like a train wreck due to ActiveRecord trying to interpret what you are saying. Typically, the first class derived from ActiveRecord :: Base is used to determine the name of the base table, and the subclasses that are defined to use Single Table Inheritance (STI) by default. You work around this using set_table_name , but as is often the case, although it can go against the grain in Rails, things often get messy.
You should be able to do this much more cleanly using mixin, as suggested by Beerlington.
module ByNameExtension def self.extended(base)
You should be able to support the extensions contained in this module. If you want to clear this even further, write an initializer that defines a method of type scoped_by_name for ActiveRecord :: Base that calls this behavior:
class ActiveRecord::Base def scoped_by_name extend ByNameExtension end end
Then you can mark all classes that require this:
class MyModel < ActiveRecord::Base scoped_by_name end
source share