我有這些模型MongoID關係查詢
class State
include Mongoid::Document
field :name
embeds_many :cities
end
class City
include Mongoid::Document
field :name
field :zip_code
embedded_in :state
references_many :organization_addresses
end
class Organization
include Mongoid::Document
field :name
references_many :organization_addresses
end
class OrganizationAddress
include Mongoid::Document
field :address
field :latitude, :type=>Float
field :longitude, :type=>Float
referenced_in :organization
referenced_in :city
end
現在,我想創建一個地址爲一個組織,並說明解決的城市,其ZIP_CODE是06511
。首先,我該如何找到嵌入狀態的城市。然後我可以如何參考它。我寫了查詢State.where("cities.zip_code"=>"06511").count
它不會返回任何數據庫中存在的城市。
我該如何搜索,然後將其引用到組織的地址?
嘿納扎爾,你有沒有找到一個解決的辦法? –