将Rails 2.3.11升级到3.1.3 - 尝试用proxy_association.owner替换proxy_owner

时间:2011-12-07 10:59:52

标签: ruby-on-rails activerecord ruby-on-rails-3.1

将内部gem从Rails 2.3.11升级到3.1.3 - 使用以下代码对动作通道进行建模:

  has_many :actions, :class_name => 'Streamer::Model::Action', :through => :action_channel_entries, :order => 'actions.id desc' do
    def publish(action)
      proxy_association.owner.publish(action)
    end

    def subscriptions
      proxy_association.owner.subscriptions
    end
  end

而不是CollectionProxy这个has_many中的self是一个ActiveRecord :: Relation,因为我的单元测试中的错误表明:

undefined local variable or method `proxy_association' for #<ActiveRecord::Relation:0x106d60f68>
from /Users/brett/.rvm/gems/ree-1.8.7-2011.03@ncsl_r313/gems/activerecord-3.1.3/lib/active_record/relation.rb:459:in `method_missing'
from /Users/brett/Projects/ncsl/app/lib/streamer/model/action_channel.rb:11:in `subscriptions'
from (irb):10

现在我只是在寻找有关如何进一步调查此问题的建议,也许是对CollectionProxy和ActiveRecord :: Relation的不同用途有所了解。

2 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情:

@association.owner

答案 1 :(得分:0)

通过此问题解决了该问题:https://github.com/rails/rails/issues/3890