Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Using ActiveRecord in subclasses

Reply
Thread Tools

Using ActiveRecord in subclasses

 
 
Paul Mckibbin
Guest
Posts: n/a
 
      01-26-2010
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:age <= 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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Paul Mckibbin
Guest
Posts: n/a
 
      01-26-2010
Reposted in the Ruby on Rails forum. Apologies.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using different iterator types in subclasses without breaking theinheritance mechanism Alfredo Di Napoli C++ 4 02-19-2012 10:19 AM
Question about using DISTINCT in ActiveRecord find method. Mufaddal Khumri Ruby 1 01-12-2006 06:43 PM
Using Rails, Anyway to build ActiveRecord to Point at Hash? Peter Kellner Ruby 0 08-05-2005 01:42 PM
Using a class namespace for subclasses Trans Ruby 10 07-26-2005 03:48 PM
validity of using subclasses in pointer-to-pointer types? Marcus Alanen C++ 1 09-07-2003 10:42 AM



Advertisments