0
有沒有辦法在Mongoid中的嵌入式文檔中找到零值?如何在Mongoid中找到無字段值的嵌入式文檔?
鑑於我有這些模型:
class Record
include Mongoid::Document
embeds_many :locations
end
class Location
include Mongoid::Document
embedded_in :record
field :special_id, type: String
end
我可以找到特定地點模型
Record.where('locations.special_id' => '123')
的具體special_id
記錄,但,如果我想要得到的位置與零special_id
的所有記錄,這有效,但會返回所有記錄。
Record.where('locations.special_id.eq' => nil)
這一次返回0結果:
Record.where('locations.special_id.exists' => false)
感謝
也許http://stackoverflow.com/a/8963075/1197775 – juanpastas 2014-09-24 05:02:26
@juanpastas這就是如果你沒有嵌入文件。如果'special_id'是'record'模型的一個字段,那麼這將起作用。 – Ben 2014-09-24 05:04:27
'Record.where('locations.special_id'=> nil)''? – 2014-09-24 05:19:27