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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Magicloud wrote:> 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)"?Adding set_table_name ''as'' to the A class may get it working. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Jun 6, 12:23 am, Magicloud <magicloud.magiclo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---