我的模型是:(帶mongoid版本2)如何用mongoid查詢空白數組的字段?
class Trip
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
field :images, :type => Array, :default => []
end
我可以搜索出的條目,其它的圖像尺寸不爲0的條件:
Trip.where(:images.size => 1).size #=>1, correct
而此方法不能用於搜索空白陣列字段:
Trip.where(:images.size => 0).size #=>0, error, as i do have many entries with default [] field.
我該如何解決它?