我使用了MongoDB,我的模型retailer
有很多stores
,我想要返回至少有一个商店的零售商。
我发现了这个问题:How can I find records by “count” of association using rails and mongoid?
但接受的答案是:
scope :with_at_least_n_stores, -> { where('stores_count >= 1') }
取决于零售商模式中的stores_count
字段,但我没有此字段。
找到零售商的任何解决方案,至少有一家商店使用范围,而不添加stores_count
字段?
答案 0 :(得分:0)
也许这个?
scope :with_at_least_n_stores, -> { stores.size > 0 }