は私が持っているレール:どのようにスコープに委任できますか?
class UserItem < ActiveRecord::Base
belongs_to :user
belongs_to :item
scope :equipped, -> { where(equipped: true) }
end
class Item < ActiveRecord::Base
has_many :user_items
has_many :users, through: :user_items
scope :armor, -> { where(type: 'Armor') }
delegate :equipped, to: :user_items
end
編集:私はしようとした場合
User.first.items.equipped
=>undefined method 'equipped' for #<ActiveRecord::Associations::CollectionProxy []>
User.first.items.armor.equipped
=>undefined method 'equipped' for #<ActiveRecord::AssociationRelation []>
がどのように私はスコープに委任することができますか?
こんにちは、私はあなたが実際にやろうとしていないかもしれない理由と、親スコープを使って子アイテムを取得するために必要なアプローチを説明しました。 – Matt
「マージ」が解決策であることを私が確信しているので、私は疑問を誤解しているはずです。がんばろう! – Matt