我不知道这是否可能,但这里有:
FruitBasket
has_many :apples
has_many :bananas
######## What to put here to access Worm through its pest_holder relationship?
Apple
has_many :worms, :as => :pest_holder
belongs_to :fruit_basket
Banana
has_many :worms, :as => :pest_holder
belongs_to :fruit_basket
Worm
belongs_to :pest_holder, :polymorphic => true
我需要能够调用的关系是什么:
red_delicious = Apple.first
red_delicious.worms.whatever
它是否通过 Apple 和 Banana 与 Worm 的多态关系获取了所有 Worm?
这似乎有点倒退,但无论如何我感谢您的帮助!如果需要任何澄清,请询问。