2013-02-07 20 views
0

我正在將舊版項目從Rails 2.3.2升級到2.3.16(由於最近公佈的漏洞),但是當我嘗試訪問has_many關聯在任何型號上,我從sanitize_sql獲得ArgumentErrorRails 2.3.16關聯在使用關聯時給出ArgumentError

class User 
    has_many :games, :dependent => destroy 
end 

class Game 
    belongs_to :user 
end 

當我嘗試並調用Game.last.user它返回正確User對象,但調用User.last.games我碰到下面的錯誤堆棧:

ArgumentError: wrong number of arguments (2 for 1) 
    from /home/username/application/shared/bundle/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/associations/association_proxy.rb:174:in `sanitize_sql' 
    from /home/username/application/shared/bundle/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/associations/association_proxy.rb:174:in `send' 
    from /home/username/application/shared/bundle/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/associations/association_proxy.rb:174:in `sanitize_sql' 
    from /home/username/application/shared/bundle/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/associations/association_collection.rb:41:in `find' 
    from /home/username/application/shared/bundle/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/associations/association_collection.rb:423:in `find_target' 
    from /home/username/application/shared/bundle/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/associations/association_collection.rb:365:in `load_target' 
    from /home/username/application/shared/bundle/ruby/1.8/gems/activerecord-2.3.16/lib/active_record/associations/association_proxy.rb:140:in `inspect' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:310:in `output_value' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:159:in `eval_input' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:271:in `signal_status' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:155:in `eval_input' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:154:in `eval_input' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:71:in `start' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:70:in `catch' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/irb.rb:70:in `start' 
    from /home/username/.rvm/rubies/ruby-1.8.7-p371/bin/irb:17 

我關於Ruby 1.8.7運行的Rails 2.3.16 ;如果還有其他細節可以幫助我診斷問題,請告訴我。

編輯

我似乎已經解決這個問題,通過編輯錯誤導致線在activerecord-2.3.16/lib/active_record/associations/association_proxy.rb文件像這樣暫時的工作:

# Forwards the call to the reflection class. 
def sanitize_sql(sql, table_name = @reflection.klass.quoted_table_name) 
    @reflection.klass.send(:sanitize_sql, sql) #, table_name) 
end 

我想,很明顯,喜歡比較長因爲我不能100%確定這不會有額外的連鎖問題。

+0

你ree版本的補丁級別是什麼?你仍然使用ree1.8.7-2012.02得到相同的錯誤?我在ree-1.8.7-2011.12 – Regedor

+0

上遇到了一些問題,我使用的是ruby-1.8.7-p371,但我會給ree一個鏡頭,看看是否有幫助。 – PaulC

+0

不,改用ree-1.8.7-2012.02似乎沒有解決問題。 – PaulC

回答

0

我有這個相同的問題,找不到是什麼原因導致它。

我也來編輯這一行的結論。我做了一個猴子初始化程序:

module ActiveRecord 
    module Associations 
    class AssociationProxy #:nodoc: 
     def sanitize_sql(sql, table_name = @reflection.klass.quoted_table_name) 
     @reflection.klass.send(:sanitize_sql, sql)#, table_name) 
     end 
    end 
    end 
end 

我希望儘快找到真正的原因,因爲這不是必須的。你的問題還有什麼進展?