Hi, I’m using ActiveRecord and ActiveSupport in a non-rails environment
to connect to multiple databases, and I’ve found the following (single
database) to cause me an error. Note that params is my database settings
and omitted for obvious reasons. pages, components, and books are all
tables in the same db.
require ‘active_record’
module TestDB
class Inherited < ActiveRecord::Base
self.logger
self.default_timezone :utc
self.establish_connection(params)
end
class Page < Inherited
puts self.name
puts self.table_name
end
class Book < ActiveRecord::Base
puts self.name
puts self.table_name
end
end
class Component < ActiveRecord::Base
puts self.name
puts self.table_name
end
outputs:
TestDB::Page <= expected
inheriteds <= Hmm, table name for the parent?
TestDB::Book <= also expected
books <= Seems to be using the Inherited connection
Component <= Yep, no module name
components <= also using the Inherited connection
Is this expected behaviour from an inherited class. Is there anyway to
scope the ActiveRecord connection without resorting to plugins or other
gems?
Mac