मैं निम्नलिखित सेट अपरेल: 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
संबंध विस्तार विधियों तक कैसे बढ़ा सकता हूं? (क्या यह सिर्फ एक बग है?)
ठीक है, नहीं है इसे "in_hand" विधि के साथ काम करने का कोई तरीका है? – Chowlett