1

I have a two models, Deal and Contact.

My Contact model is embedded inside the Deal model, and it can be many contacts inside one Deal.

How can I get Contacts with deal_ids ?

EX: deal_ids = ["a9s82sj", "kswid"] I want to get all Contacts that are inside 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
  • 1
    The `has_and_belongs_to_many` relation is not embedded but in fact only "embeds" the `ObjectId` from the `_id` field of the related document. Which field in which class are you trying to match on with `["a9s82sj", "kswid"]`? Neither of the classes you have listed show any defined fields other than the relation in your question. – Neil Lunn Jun 28 '17 at 05:46

0 Answers0