Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 2.3.16使用关联时出现错误的关联_Ruby On Rails_Associations_Rails Activerecord - Fatal编程技术网

Ruby on rails Rails 2.3.16使用关联时出现错误的关联

Ruby on rails Rails 2.3.16使用关联时出现错误的关联,ruby-on-rails,associations,rails-activerecord,Ruby On Rails,Associations,Rails Activerecord,我正在将一个遗留项目从Rails 2.3.2升级到2.3.16(由于最近公开的漏洞),但是当我尝试访问任何模型上的有许多关联时,我从清理sql中得到一个参数错误 class User has_many :games, :dependent => destroy end class Game belongs_to :user end 当我尝试调用Game.last.user时,它返回正确的user对象,但调用user.last.games时,我得到以下错误堆栈: Argument

我正在将一个遗留项目从Rails 2.3.2升级到2.3.16(由于最近公开的漏洞),但是当我尝试访问任何模型上的
有许多关联时,我从
清理sql
中得到一个
参数错误

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\u record/associations/association\u 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%肯定这不会带来额外的连锁反应问题。

我也有同样的问题,无法找到原因

我也得出了编辑这一行的结论。我做了一个猴子补丁初始化器:

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

我希望我能尽快找到真正的原因,因为这不必要。您的问题还有什么进展吗?

您的ree版本的补丁级别是多少?使用ree1.8.7-2012.02,您是否仍然会遇到相同的错误?我在ree-1.8.7-2011中遇到了一些问题。12我使用的是ruby-1.8.7-p371,但我会给ree一个机会,看看这是否有帮助。不,改为ree-1.8.7-2012.02似乎并没有解决问题。