You could achieve what you want with STI, write a before_save callback
that changes the type to 'InnerCity' when you save a Location with a
postcode within the 2000, 2001 range. It feels wrong to me but it
should work.
named_scopes would be nicer for this. It used to be a plugin
(has_finder), so you might be able to find it and get that working in
rails 1.2.3? I can't remember when the plugin was first created.
On 14/08/2009, at 11:07 AM, Sonia Hamilton wrote:
> That would be in the controller not the model, wouldn't it?
>
> Whilst I could do that I really want a different model, so I can
> implement different logic for InnerCity locations (eg increase the
> price, decrease the size, ... :-) ).
> Sonia Hamilton.
>
>
> Jonathan Clarke wrote:
>>
>> Something like this?
>>
>> @foo = InnerCity.find(:all, :conditions=>{:postcode=>[2001, 2002]})
>>
>> Jonathan
>>
>>
>> 2009/8/14 Sonia Hamilton <[email protected]>:
>>
>>> Hi guys, I've been lurking around the RORO list for a while. I don't
>>> know whether it's appropriate to ask rails tech questions here,
>>> but I'll
>>> post anyway and see what happens...
>>>
>>> My question is: if I subclass a model, how do I limit the records
>>> retrieved in the subclass?
>>>
>>> eg I have:
>>>
>>>> % gem list --local | egrep 'rails|activerecord'
>>>> activerecord (1.15.3)
>>>> rails (1.2.3)
>>>>
>>>> class Location < ActiveRecord::Base
>>>> # stuff
>>>> end
>>>>
>>>> class InnerCity < Location
>>>> # additional stuff
>>>> end
>>>>
>>> In the InnerCity class, I only want to see the rows that would
>>> result
>>> from a where clause of "postcode in (2000,2001)". How would I do
>>> this?
>>>
>>> I know about polymorphism and :polymorphic and :as (and that would
>>> be
>>> the ideal solution). But I'm wondering is there's another way...
>>>
>>> Thanks,
>>>
>>> --
>>> Sonia Hamilton.
>>>
>>>
>>>
>>>
>>
>>
>>
>
> >
Cheers,
Gareth Townsend
http://www.garethtownsend.info
http://www.melbournecocoaheads.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en
-~----------~----~----~----~------~----~------~--~---