squeel icon indicating copy to clipboard operation
squeel copied to clipboard

Squeel incompatible with Rails 4.2: Wrong number of arguments with `.find(id)`

Open doits opened this issue 10 years ago • 6 comments

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?

doits avatar Dec 09 '14 16:12 doits

Yes, I found the error too. It needs an update.

bigxiang avatar Dec 15 '14 21:12 bigxiang

Such expressions are also broken: Category.where(name: 'some name here')

Envek avatar Dec 18 '14 09:12 Envek

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

nulian avatar Dec 24 '14 01:12 nulian

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 !

Envek avatar Dec 24 '14 15:12 Envek

+1, getting this error on rails 4.2, and fixed by gem 'squeel', github: 'danielrhodes/squeel'

m-shirshendu avatar Jan 08 '15 14:01 m-shirshendu

:+1:

fake-or-dead avatar Jan 09 '15 06:01 fake-or-dead