squeel
squeel copied to clipboard
Squeel incompatible with Rails 4.2: Wrong number of arguments with `.find(id)`
Adding the squeel gem in Rails 4.2.0.rc2 and trying a basic find yields this:
[2] pry(main)> Task.find(1)
ArgumentError: wrong number of arguments (2 for 1)
from .../vendor/bundle/ruby/2.1.0/gems/activerecord-4.2.0.rc2/lib/active_record/relation/query_methods.rb:964:in `create_binds'
Looks like it must be updated for Rails 4.2.0?
Yes, I found the error too. It needs an update.
Such expressions are also broken: Category.where(name: 'some name here')
It is a pretty easy fix This below:
def expand_attrs_from_hash(opts)
opts = ::ActiveRecord::PredicateBuilder.resolve_column_aliases(klass, opts)
bv_len = bind_values.length
tmp_opts, bind_values = create_binds(opts, bv_len)
self.bind_values += bind_values
attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts)
attributes.values.grep(::ActiveRecord::Relation) do |rel|
self.bind_values += rel.bind_values
end
attributes
end
Has to become:
def expand_attrs_from_hash(opts)
opts = ::ActiveRecord::PredicateBuilder.resolve_column_aliases(klass, opts)
tmp_opts, bind_values = create_binds(opts)
self.bind_values += bind_values
attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts)
attributes.values.grep(::ActiveRecord::Relation) do |rel|
self.bind_values += rel.bind_values
end
attributes
end
It seems to be already proposed in #354, so waiting until it gets merged and released.
Meanwhile it can be used from GitHub, change line in Gemfile to:
gem 'squeel', github: 'danielrhodes/squeel'
At least it works for me, thanks to @danielrhodes !
+1, getting this error on rails 4.2, and fixed by gem 'squeel', github: 'danielrhodes/squeel'
:+1: