【发布时间】:2011-10-04 10:57:48
【问题描述】:
我有这些模型
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
现在我想为一个组织创建一个地址,并将该地址引用到一个邮政编码为06511 的城市。首先我怎么能找到嵌入状态的城市。然后我怎么能引用它。我写了查询State.where("cities.zip_code"=>"06511").count 它不返回任何东西,因为数据库中有城市。
我如何搜索它,然后将其引用到组织的地址?
【问题讨论】:
-
嘿 Nazar,你找到解决办法了吗?
标签: ruby-on-rails-3 mongodb mongoid