Mongoid查询带有父ID的嵌入文档

时间:2017-06-28 04:39:39

标签: ruby-on-rails mongodb mongoid embedded-documents

我有两个型号,Deal和Contact。

我的联系人模型嵌入在交易模型中,一个交易中可以有多个联系人。

如何通过deal_ids获取联系人?

EX: deal_ids = [“a9s82sj”,“kswid”] 我想得到所有在deal_ids = deal_ids

内的联系人
class Deal
  include Mongoid::Document
  include Mongoid::Pagination
  include Mongoid::Timestamps
  include Mongoid::IndexedFields
  include Mongoid::Search

  has_and_belongs_to_many :contacts
end

class Contact
  include Mongoid::Document
  include Mongoid::Pagination
  include Mongoid::Timestamps
  include Mongoid::IndexedFields

  has_and_belongs_to_many :deals, inverse_of: :contacts, validate: false
end

0 个答案:

没有答案