I’ve got something like this:
class Position < ActiveRecord::Base
end
class CartItem < Position
validates_uniqueness_of :product_id
end
When I try to save CartItem I get this error:
ArgumentError: wrong number of arguments (1 for 2)
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:758:in
exists?' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:758:in
validates_uniqueness_of’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2148:in
with_scope' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2156:in
with_exclusive_scope’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:757:in
validates_uniqueness_of' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:399:in
validates_each’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in
each' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in
validates_each’
from
/home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:182:in
call' from /home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:182:in
evaluate_method’
from
/home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:166:in
call' from /home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in
run’
from
/home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in
each' from /home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in
send’
from
/home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in
run' from /home/joaz/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:276:in
run_callbacks’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:1029:in
valid_without_callbacks?' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:315:in
valid?’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:1008:in
save_without_dirty' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/dirty.rb:79:in
save_without_transactions’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:229:in
send' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:229:in
with_transaction_returning_status’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in
transaction' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:182:in
transaction’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:228:in
with_transaction_returning_status' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:196:in
save’
from
/home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:208:in
rollback_active_record_state!' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:196:in
save’
Putting validates_uniqueness_of in the Position model works fine. It
doesn’t work in any inherited class. This seems to be a regression issue
on Rails 2.3, works fine on previous rails versions.