Hi.
I do not think that this is a bug, they have just changed some methods
there.
In class_methods.rb:
used to be:
def retrieve_records(id_arrays, find_options = {})
result = []
# get objects for each model
id_arrays.each do |model, id_array|
next if id_array.empty?
begin
model = model.constantize
rescue
raise "Please use ':store_class_name => true' if you want to
use multi_search.\n#{$!}"
end
# check for include association that might only exist on some
models in case of multi_search
filtered_include_options = []
if include_options = find_options[:include]
include_options.each do |include_option|
filtered_include_options << include_option if
model.reflections.has_key?(include_option.is_a?(Hash) ?
include_option.keys[0].to_sym : include_option.to_sym)
end
end
filtered_include_options=nil if filtered_include_options.empty?
# fetch
tmp_result = nil
model.send(:with_scope, :find => find_options) do
tmp_result = model.find( :all, :conditions => [
"#{model.table_name}.#{model.primary_key} in (?)",
id_array.keys ],
:include => filtered_include_options)
end
and now it is:
def retrieve_records(id_arrays, find_options = {})
result = []
# get objects for each model
id_arrays.each do |model, id_array|
next if id_array.empty?
begin
model = model.constantize
rescue
raise "Please use ':store_class_name => true' if you want
to use multi_search.\n#{$!}"
end
# merge conditions
conditions = combine_conditions([
"#{model.table_name}.#{model.primary_key} in (?)",
id_array.keys ],
find_options[:conditions])
# check for include association that might only exist on
some models in case of multi_search
filtered_include_options = []
if include_options = find_options[:include]
include_options = [ include_options ] unless
include_options.respond_to?(:each)
include_options.each do |include_option|
filtered_include_options << include_option if
model.reflections.has_key?(include_option.is_a?(Hash) ?
include_option.keys[0].to_sym : include_option.to_sym)
end
end
filtered_include_options = nil if
filtered_include_options.empty?
# fetch
tmp_result = model.find(:all, find_options.merge(:conditions
=> conditions,
:include =>
filtered_include_options))
# set scores and rank
tmp_result.each do |record|
record.ferret_rank, record.ferret_score =
id_array[record.id.to_s]
end
# merge with result array
result.concat tmp_result
end
You got the error, because of this difference:
old way to generate SQL query:
model.send(:with_scope, :find => find_options) do
tmp_result = model.find( :all, :conditions => [
"#{model.table_name}.#{model.primary_key} in (?)",
id_array.keys ],
:include => filtered_include_options)
end
new way to generate the SQL query:
tmp_result = model.find(:all, find_options.merge(:conditions =>
conditions,
:include => filtered_include_options))
You have to put the options and find_options in separate hash when
passing them to search, as is described here:
http://projects.jkraemer.net/rdoc/acts_as_ferret/classes/ActsAsFerret/ClassMethods.html#M000023
I also spotted a bug into next method (count_records) that will generate
an invalid SQL query if you use :select => “articles.*” in find_options
with a :join option to select only records for articles table. So, for
now I stick with the old version.
I haven’t yet spotted all other changes, so for now I stick with the
other version