I wish to use this method like
@results = Candidate.all.match_against(options)
, where “options” is an array of integers. And it should return me all candidates with their match score.
In Candidate model I have a method for matching candidates against options given as a parameter.
def self.match_against(cu_options)
select("candidates.id, candidates.first_name, candidates.last_name, candidates.number,
sum(case when c_answers.option_id in (?) then 1 else 0 end) as score", cu_options)
.joins("join answers as c_answers on c_answers.user_id = candidates.user_id")
.joins("join options on c_answers.option_id = options.id")
.where("options.ordering >= 0")
.group("candidates.id, candidates.number, candidates.first_name, candidates.last_name")
end
For some reason when I’m calling this method it gives me an error
ArgumentError: wrong number of arguments (2 for 1)
from /home/mika/.rvm/gems/ruby-1.9.2-p180@vaalikone/gems/activerecord-3.0.7/lib/active_record/relation/query_methods.rb:34:in `select'
from /home/mika/.rvm/gems/ruby-1.9.2-p180@vaalikone/gems/activerecord-3.0.7/lib/acteve_record/base.rb:442:in `select'
from /home/mika/projects/vaalikone/app/models/candidate.rb:35:in `match_against'
...
I have no idea where the second argument is coming from. I’m passing in only one argument. I’m using postgresql.
Actually, you are passing two arguments to the select scope:
sum(case when c_answers.option_id in (?) then 1 else 0 end) as score”
Is there any reason for that?