Active Record Inheritance with out using type_id

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

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.

Brian C. 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!!

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