# Single Table Inheritance and :conditions

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-and-conditions/113875>\
**Category:** Rails\
**Created:** [September 5, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-conditions/113875 "2007-09-05T20:36:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tony\_from\_KY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e56c9b/32.png) [@tony\_from\_KY](https://www.ruby-forum.com/u/tony_from_KY)\
**Post date:** [September 5, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-conditions/113875/1 "2007-09-05T20:36:56Z")

</div>

Single Table Inheritance question.

class Employee is the master model (table is employees)  
class Cog is the subclass model, and uses single table inheritance to  
be a subclass of Employee  
class Blurfl is a normal model (table is blurfls)

in cog.rb, I have something like:

def foo  
Cog.find(:all, :include=\>‘blurfl’, :condition=\> [“cogs.status =  
‘Active’”]  
end

So we’re joining active cogs and blurfls. Now, and this is the thang,  
assume that the blurlfs and cogs tables both have a status column.

The problem is that the conditional statement above won’t work. There  
isn’t a cogs table. And I have to qualify the column name since it  
exists in blurfls and employees.

Rails seems to have all the information it needs to do this  
translation.

I find it egregious that I’d have to refer to “employees.status”  
instead of “cogs.status” in that conditional. Is there a way around  
this?

---

<div class="post-metadata">

**Author:** ![tony\_from\_KY](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e56c9b/32.png) [@tony\_from\_KY](https://www.ruby-forum.com/u/tony_from_KY)\
**Post date:** [September 5, 2007, 10:21pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-conditions/113875/2 "2007-09-05T22:21:19Z")

</div>

tony\_from\_KY wrote:

> in cog.rb, I have something like:
> 
> def foo  
> Cog.find(:all, :include=\>‘blurfl’, :condition=\> [“cogs.status =  
> ‘Active’”]  
> end

> I find it egregious that I’d have to refer to “employees.status”  
> instead of “cogs.status” in that conditional. Is there a way around  
> this?

well, when you offer a conditions key as a string, you are adding a  
string to manually be inserted into the SQL query.

I’d suggest if you want it clear do the following;

:conditions =\> ["#{Cog.table\_name}.status = ?", “Active”]
