我的下一個型號查詢,使用Mongoid:Mongoid其中使用count
class Album
have_many :images
end
class Image
belongs_to :album
end
我想只有有任何圖片專輯:
Album.all.select{ |a| a.images.count > 0 }
但它返回一個數組,我需要一個Mongoid ::標準。我嘗試使用類似的東西:
Album.where("this.images.count > 0")
它總是返回0個元素。 我該怎麼做 ?
我不知道,但這個'Album.joins(:圖像)'應該返回一個有至少一個圖像的相冊數組 - 檢查你的身邊:我不太確定。 – MrYoshiji