【发布时间】:2012-12-06 20:21:02
【问题描述】:
我想拉出所有至少有一个“CEO”职位头衔的公司。
我可以将它与每个表的查询和一个相交一起破解(我知道...没有连接 http://mongoid.org/en/mongoid/docs/tips.html#relational_associations 和 N+1 problem in mongoid,我可以在公司中嵌入职位),但任何方式都可以做某事喜欢:
Company.includes(:positions).where("positions.title" => "CEO")?
谢谢:
class Position
include Mongoid::Document
field :title, type: String
field :profile_id, type: String
field :tenure, type: BigDecimal
belongs_to :company, index: true
class Company
include Mongoid::Document
field :name, type: String
field :linkedin_id, type: String
field :positions_count, type: Integer #Mongo Index
belongs_to :industry, index: true
has_many :positions
index({ positions_count: 1}, {background: true})
【问题讨论】:
标签: ruby-on-rails mongodb mongoid