Does anyone know how to do the following? I have 3 different AR classes that all map to the same table. The only difference between this AR classes is that they should only return record that match a certain condition. For example, Foo should only return records from table ''list'' that follow the condition ftype="foo", where as Bar, on the other hand, should only return records that follow the condition ftype="bar". I know I can specify conditions and finder_sql with relationships, but I want to define a base level condition for the model. Is this possible? Any suggestions? -Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060112/c276b754/attachment.html
Mark Reginald James
2006-Jan-12 23:26 UTC
[Rails] Re: ActiveRecord models w/ base condition
Belorion wrote:> Does anyone know how to do the following? I have 3 different AR classes > that all map to the same table. The only difference between this AR > classes is that they should only return record that match a certain > condition. > > For example, Foo should only return records from table ''list'' that > follow the condition ftype="foo", where as Bar, on the other hand, > should only return records that follow the condition ftype="bar". > > I know I can specify conditions and finder_sql with relationships, but I > want to define a base level condition for the model. Is this possible? > Any suggestions?Single table inheritance will do what you want. Read about it here: http://api.rubyonrails.com/classes/ActiveRecord/Base.html -- We develop, watch us RoR, in numbers too big to ignore.
On 1/12/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> > Single table inheritance will do what you want. Read about it here: > http://api.rubyonrails.com/classes/ActiveRecord/Base.html >Great, thanks. I''m not sure why that didn''t occur to me in the first place! Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060113/052f14bd/attachment.html