# Active Record Inheritance with out using type\_id

**URL:** <https://www.ruby-forum.com/t/active-record-inheritance-with-out-using-type-id/192493>\
**Category:** Ruby\
**Created:** [July 31, 2010, 3:13pm UTC](https://www.ruby-forum.com/t/active-record-inheritance-with-out-using-type-id/192493 "2010-07-31T15:13:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morrisminor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@morrisminor](https://www.ruby-forum.com/u/morrisminor)\
**Post date:** [July 31, 2010, 3:13pm UTC](https://www.ruby-forum.com/t/active-record-inheritance-with-out-using-type-id/192493/1 "2010-07-31T15:13:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![morrisminor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@morrisminor](https://www.ruby-forum.com/u/morrisminor)\
**Post date:** [August 1, 2010, 1:25pm UTC](https://www.ruby-forum.com/t/active-record-inheritance-with-out-using-type-id/192493/2 "2010-08-01T13:25:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![morrisminor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@morrisminor](https://www.ruby-forum.com/u/morrisminor)\
**Post date:** [August 1, 2010, 5:01pm UTC](https://www.ruby-forum.com/t/active-record-inheritance-with-out-using-type-id/192493/3 "2010-08-01T17:01:36Z")

</div>

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!!
