Single Table Inheritance and :conditions

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?

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”]