Hi all,
I have a table called ''report'' with the model defined as such
class Report < ActiveRecord::Base
     belongs_to(:company)
     belongs_to(:source)
     belongs_to(:pp_code)
     belongs_to(:status)
     has_many(:log_entry)
end
In one of my controllers, I''m trying to do some optimizations and  
tried to run the query
reports = Report.find(:all, :include => :status, :conditions =>  
[query, ppCodes])
where the query is
pp_code_id IN (?) and (source_id = 1 or source_id = 4 or source_id = 5)
The exception I''m receiving is
undefined method `include?'' for nil:NilClass
/usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/ 
base.rb:1040:in `sanitize_sql''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/ 
base.rb:897:in `add_conditions!''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/ 
associations.rb:875:in
`construct_finder_sql_with_included_associations''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/ 
associations.rb:865:in `select_all_rows''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/ 
associations.rb:778:in `find_with_associations''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/ 
base.rb:396:in `find''
#{RAILS_ROOT}/app/controllers/report_controller.rb:89:in
`create_report''
dumping out the sql active records was generating resulted in the  
following:
SELECT report.published AS t0_r6, report.user_modified AS t0_r7,  
report.created_at AS t0_r8, report.resolved AS t0_r10,  
report.modified_at AS t0_r9, status.id AS t1_r0, report.resolved_at  
AS t0_r11, status.name AS t1_r1, report.resolution_description AS  
t0_r12, report.id AS t0_r0, status.user_modified AS t1_r2,  
report.company_id AS t0_r1, status.modified_at AS t1_r3,  
report.source_id AS t0_r2, report.pp_code_id AS t0_r3,  
report.status_id AS t0_r4, report.description AS t0_r5 FROM report   
LEFT OUTER JOIN status ON status.id = report.statu_id
Looking at the join, I see that the foreign key relationship is  
incorrect.
LEFT OUTER JOIN status ON status.id = report.statu_id
it should read
LEFT OUTER JOIN status ON status.id = report.status_id
Looking at the source code, it looks as if :
The problem (or at least a problem), is occurring in the  
associations.rb file in the association_join method.  The code  
snippet looks like:
     when :belongs_to
         " LEFT OUTER JOIN #{reflection.klass.table_name} ON " +
         "#{reflection.klass.table_name}.# 
{reflection.klass.primary_key} = " +
         "#{table_name}.#{reflection.options[:foreign_key] ||  
reflection.klass.table_name.classify.foreign_key} "
the values for
reflection.options[:foreign_key] = NULL
reflection.klass.table_name.classify.foreign_key = statu_id
So I guess this is where the problem is.  I was wondering if anyone  
can point out to me where this last variable obtains its value.  I  
checked my database foreign key declarations and it looks fine.  the  
column is properly named.  In fact, this column is used in many other  
places without any problems.
Any help would be much appreciated.
Thanks in advance for any help.
I''m running on Mac OS X (10.4.2) with rails 1.8.2. with a mysql  
4.1.15 database.
+s.park