我用的是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字段的情况下找到至少有一家商店使用scope的零售商?
发布于 2014-11-03 23:25:57
也许是这个?
scope :with_at_least_n_stores, -> { stores.size > 0 }https://stackoverflow.com/questions/26716617
复制相似问题