From: Austin Fagan on
Hi,

I am writing a script that queries a database for records with either
the value '333' or '444' in a field called pin_id in a table called pop.
Currently I have created a model called GoodPop using set_table_name
:pop
I have overrided the first, last and all methods to return only those
records with a pin_id of either '333' or '444'.

This doesnt feel right. I was thinking of using the inheritance_column
to change the type to the pin_id column but then I would need to call
the model name to either 333 or 444- is this right?

Can anyone offer any suggestions?

Thanks
MM
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Austin Fagan wrote:0
> I am writing a script that queries a database for records with either
> the value '333' or '444' in a field called pin_id in a table called pop.
> Currently I have created a model called GoodPop using set_table_name
> :pop
> I have overrided the first, last and all methods to return only those
> records with a pin_id of either '333' or '444'.

Don't Do That.

Look up the AR documentation for named scopes and anonymous scopes.
--
Posted via http://www.ruby-forum.com/.

From: Austin Fagan on
Brian Candler wrote:
> Austin Fagan wrote:0
>> I am writing a script that queries a database for records with either
>> the value '333' or '444' in a field called pin_id in a table called pop.
>> Currently I have created a model called GoodPop using set_table_name
>> :pop
>> I have overrided the first, last and all methods to return only those
>> records with a pin_id of either '333' or '444'.
>
> Don't Do That.
>
> Look up the AR documentation for named scopes and anonymous scopes.

Thanks Brian, using named_scopes!!
--
Posted via http://www.ruby-forum.com/.