Rails:: inverse_of и расширения ассоциации

У меня есть следующая настройка

class Player < ActiveRecord::Base
  has_many :cards, :inverse_of => :player do
    def in_hand
      find_all_by_location('hand')
    end
  end
end

class Card < ActiveRecord::Base
  belongs_to :player, :inverse_of => :cards
end

Это означает, что работает следующее:

p = Player.find(:first)
c = p.cards[0]
p.score # => 2
c.player.score # => 2
p.score += 1
c.player.score # => 3
c.player.score += 2
p.score # => 5

Но следующее работает иначе:

p = Player.find(:first)
c = p.cards.in_hand[0]
p.score # => 2
c.player.score # => 2
p.score += 1
c.player.score # => 2
c.player.score += 2
p.score # => 3

d = p.cards.in_hand[1]
d.player.score # => 2

Как я могу сделать : отношение inverse_of распространяется на методы расширения? (Это просто ошибка?)

9
задан John Bachir 24 April 2011 в 07:26
поделиться