Rails 3 と MongoDB (mongoid アダプター) を使用してアプリケーションを構築しています。子レコードで特定の条件を持つ親レコードを見つけるのに苦労しています。
class Food
include Mongoid::Document
has_many :subscriptions, as: :subscribable
end
class Subscription
include Mongoid::Document
field :subscriber_id
belongs_to :subscribable, polymorphic: true
belongs_to :subscriber
end
特定のユーザーが購読していない食品を選択したい。
これが機能しないクエリです。
Food.not_in('subscriptions.subscriber_id' => [User.first.id])
しかし、それはすべての食べ物を返します。クエリの何が問題になっていますか?
どんな助けでも大歓迎です。
ありがとう