Could I use inherited model?

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.

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.

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs