views:

88

answers:

1

I just upgraded to rails 2.3.5 and a find statement with some eager loading that was working perfectly before, suddenly stopped working.

Advertisement.find :all, :include => [{:user => :contact}, {:apartment => {:building => :address}}], :conditions => [query_info[1]], :order => query_info[0]

This is the error I get

Mysql::Error: Unknown column 'company_id' in 'where clause': SELECT * FROM `advertisements` WHERE (company_id = 10 AND on_market = 1)

The reason the column isn't found is because none of the tables that I want included, have been included? As far as I know the syntax for the find statement is still correct in the newest version of rails, so what gives?

+3  A: 

The problem wasn't in my include statement it was in the conditions. In the older version of rails it was okay to do this

conditions => " company_id = 10 "

where company_id is a column in one of the tables in the include statement. This doesn't work anymore, you need to include the table name now. I'm guessing because rails does some fancy parsing now. This is what works for me now.

conditions => " users.company_id = 10 "
Janak