Forum: Ruby on Rails Could I use inherited model?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Magicloud (Guest)
on 2007-06-06 11:24
(Received via mailing list)
Like I have a class A and a class B, A < B, B < ActiveRecord::Base. as
and bs are two different table in database, as has bs's columns. (I
use postgresql's inherit table).

Now I do 'A.find(:all, conditions => "acol1 = 0")', acol1 does exists
in bs.
"ActiveRecord::StatementInvalid" throwed, bs does not have acol1
column. "select * from bs where (acol1 = 0)"

How to resolve this? Why A.find does not do "select * from as where
(acol1 = 0)"?
Thanks.
Mark Reginald J. (Guest)
on 2007-06-06 13:30
(Received via mailing list)
Magicloud wrote:
> (acol1 = 0)"?
Adding

set_table_name 'as'

to the A class may get it working.

--
We develop, watch us RoR, in numbers too big to ignore.
MichaelLatta (Guest)
on 2007-06-06 21:04
(Received via mailing list)
ActiveRecord supports single table inheritance.  The table name is
taken from the immediate subclass of ActiveRecord::Base.

You can place a type column in this table to support Ruby subclasses,
but all columns and all records must be in one table.

The only other option (which I have not tried) is to mark the
immediate subclass of ActiveRecord::Base as abstract in which case all
subclasses will each be in their own table.   But, then all
associations that reference any of those classes must be polymorphic
associations.

Michael
This topic is locked and can not be replied to.