title: Query to find all messages a user is participating in
body: <p>I'm creating a messaging system. A user can start a conversation by messaging multiple recipients who in turn can reply back.</p>
  
  <p>I want to find all conversations a user is participating in. Ie. conversations where they have either authored a message or were a recipient of a message in the conversation.</p>
  
  <p>Currently my models looks like this</p>
  
  <pre><code># Message
  belongs_to :conversation
  belongs_to:user #author
  has_many :receipts
  has_many :recipients, :through =&gt; :receipts
  
  # Conversation
  has_many :messages
  
  # User
  has_many :receipts
  has_many :incoming_messages, through: :receipts, :class =&gt; 'Message'
  
  # Receipt
  belongs_to :message
  belongs_to :user
  </code></pre>
  
  <p>I want to create a scope on Conversation to achive something like this</p>
  
  <pre><code>Conversation.involving(user) 
  </code></pre>
  
  <p>Not sure how to write the scope / sql for this. It feels like I need the equivalent of an OR statement in there.</p>
  
  <p>ie. in PSEUDO CODE</p>
  
  <pre><code>conversations where (messages.recipient_ids include user.id OR  messages.user_id == user.id)
  </code></pre>
  
  <p>I'm assuming ive modeled the system correctly. If not any better schema suggestions would also be greatly appreciated.</p>
  
  <p>Can anyone help with either.</p>