Brian V. Hughes
2005-Aug-05 17:59 UTC
[RE-POST] Finding rows in table a with zero related rows in table b, part ii
Just a quick re-post of my query from the other day. If I could get any help with the nature of the error message that I''m receiving when I try to call my "unassigned_list" method, that would be a big help. Normally, I wouldn''t re-post something after just 1 day, but I''m under some deadline pressure and this is really stopping my progress. Thanks for any assistance... -Brian ------------------------ OK. After a little more digging in MySQL''s manual on SubSelects, I''ve come up with this finder_sql entry in my model declaration for "unassigned_applicants": class District < ActiveRecord::Base has_many :interviewers, :order => "lname, fname" has_many :applicants has_many :unassigned_applicants, :class_name => "Applicant", :finder_sql => "select a.* from applicants a left join applicants_interviewers ai " + "on a.id = ai.applicant_id where ai.applicant_id is null" end Running that SQL through the mysql command-line tool returns exactly the data I''m looking for. However, in my district_controller.rb file, I''ve got this method: def unassigned_list @dist = District.find( params[:dist_id] ) @applicants = @dist.unassigned_applicants.find( :all ) @sub_title = "Unassigned Applicants (" + @applicants.size.to_s + ")" render :template => "district/app_list" end When I go to the page that calls this method, it throws back this error: NoMethodError in District#unassigned_list undefined method `expects_array?'' for #<Array:0x2271d04> I have no idea what this is trying to tell me. What is the expects_array? method doing? Or trying to do? -Brian
Tyler Kiley
2005-Aug-05 18:29 UTC
Re: [RE-POST] Finding rows in table a with zero related rows in table b, part ii
Can we see the stack trace? Tyler On 8/5/05, Brian V. Hughes <brianvh-ilmOVS5JQ6Xj7r8U7pfrKh2eb7JE58TQ@public.gmane.org> wrote:> > Just a quick re-post of my query from the other day. If I could get any > help with the nature of the error message that I''m receiving when I try > to call my "unassigned_list" method, that would be a big help. Normally, > I wouldn''t re-post something after just 1 day, but I''m under some > deadline pressure and this is really stopping my progress. > > Thanks for any assistance... > > -Brian > > ------------------------ > > OK. After a little more digging in MySQL''s manual on SubSelects, I''ve > come up with this finder_sql entry in my model declaration for > "unassigned_applicants": > > class District < ActiveRecord::Base > has_many :interviewers, > :order => "lname, fname" > has_many :applicants > has_many :unassigned_applicants, > :class_name => "Applicant", > :finder_sql => "select a.* from applicants a left join > applicants_interviewers ai " + > "on a.id = ai.applicant_id where ai.applicant_id is null" > end > > Running that SQL through the mysql command-line tool returns exactly the > data I''m looking for. However, in my district_controller.rb file, I''ve > got this method: > > def unassigned_list > @dist = District.find( params[:dist_id] ) > @applicants = @dist.unassigned_applicants.find( :all ) > @sub_title = "Unassigned Applicants (" + @applicants.size.to_s + ")" > render :template => "district/app_list" > end > > When I go to the page that calls this method, it throws back this error: > > NoMethodError in District#unassigned_list > undefined method `expects_array?'' for #<Array:0x2271d04> > > I have no idea what this is trying to tell me. What is the > expects_array? method doing? Or trying to do? > > -Brian > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Brian V. Hughes
2005-Aug-05 19:06 UTC
Re: [RE-POST] Finding rows in table a with zero related rows in table b, part ii
Tyler Kiley wrote:> Can we see the stack trace? > > TylerSure thing. I''ve looked at this before, but not knowing the internals of Rails, it almost never makes any sense to me. ;) -Brian /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/associations/association_proxy.rb:24:in `send'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/associations/association_proxy.rb:24:in `method_missing'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/associations/has_many_association.rb:64:in `find'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:756:in `send'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:756:in `perform_action_without_filters'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/filters.rb:295:in `perform_action_without_benchmark'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `measure'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/rescue.rb:80:in `perform_action'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:356:in `send'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:356:in `process'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/dispatcher.rb:32:in `dispatch'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/webrick_server.rb:105:in `handle_dispatch'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/webrick_server.rb:71:in `service'' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' /usr/local/lib/ruby/1.8/webrick/server.rb:155:in `start_thread'' /usr/local/lib/ruby/1.8/webrick/server.rb:144:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' /usr/local/lib/ruby/1.8/webrick/server.rb:94:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:89:in `each'' /usr/local/lib/ruby/1.8/webrick/server.rb:89:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/webrick_server.rb:57:in `dispatch''
Brian V. Hughes
2005-Aug-05 19:31 UTC
Re: [RE-POST] Finding rows in table a with zero related rows in table b, part ii
Wow... responding to my own question twice in a single day. Never done that before. :) I''ve got my problem licked. Turns out I was handling the join stuff in the wrong location. Once I moved the join into the "find.(:all...)" statement, it worked like a charm: def unassigned_list @dist = District.find( params[:dist_id] ) @applicants = @dist.applicants.find( :all, :conditions => "applicants_interviewers.applicant_id is null " + "and applicants.decision != ''U3''", :order => @app_sort, :joins => "left join applicants_interviewers " + "on applicants.id = applicants_interviewers.applicant_id" ) @sub_title = "Unassigned Applicants (" + @applicants.size.to_s + ")" render :template => "district/app_list" end Plus I was able to easily account for the extra condition this way. This was thanks to a response from Rick Olsen in the "Using find() in a habtm" thread. I''m still interested in why I was getting the error and what the stack trace shows. So if that get''s posted to the list, that would be cool. But I think I''m all set now. Oh yeah... Rails is awesome! :) -Brian Brian V. Hughes wrote:> OK. After a little more digging in MySQL''s manual on SubSelects, I''ve > come up with this finder_sql entry in my model declaration for > "unassigned_applicants": > > class District < ActiveRecord::Base > has_many :interviewers, > :order => "lname, fname" > has_many :applicants > has_many :unassigned_applicants, > :class_name => "Applicant", > :finder_sql => "select a.* from applicants a left join > applicants_interviewers ai " + > "on a.id = ai.applicant_id where ai.applicant_id is > null" > end > > Running that SQL through the mysql command-line tool returns exactly the > data I''m looking for. However, in my district_controller.rb file, I''ve > got this method: > > def unassigned_list > @dist = District.find( params[:dist_id] ) > @applicants = @dist.unassigned_applicants.find( :all ) > @sub_title = "Unassigned Applicants (" + @applicants.size.to_s + > ")" > render :template => "district/app_list" > end