title: Mongoid habtm selection
body: <p>I am trying to figure out if there is a one liner to check to see if a pair is in the habtm</p>
  
  <p>Conversation.in(participant_ids: [current_user.id, params[:recipient_id]]).first_or_create</p>
  
  <p>So basically I need to check if a pair of [Sender, Receiver] or [Receiver, Sender] exists already. If so, return the conversation id. If not, create one.</p>
  
  <p>I have tried .in, and .where, but they don't work all the time. Any ideas?</p>
  
  <pre><code>class Conversation
    include Mongoid::Document
    include Mongoid::Timestamps
  
    has_and_belongs_to_many :participants, :class_name =&gt; 'User'
    embeds_many :messages
  end
  
  def create
    @conversation = Conversation.any_of({participant_ids: [current_user.id, params[:recipient_id]]},
    {participant_ids: [params[:recipient_id], current_user.id]}).first
  
    if @conversation.nil?
      @conversation = Conversation.create(participant_ids: [current_user.id, params[:recipient_id]])
    end
    render json: { conversation_id: @conversation.id.to_s }
  end
  </code></pre>
  
  <p>So this is the Model and method I have that is working, but it seems like there should be an easier way to do this.</p>