title: Filtering multiple conditions through associated objects using ransack
body: <p>I am using Ransack to provide data filters.</p>
  
  <p>The main User model has the following association:
  <code>user has_many trips, through registrations</code></p>
  
  <p>The basic search conditions such as <code>user's name=xyz and trip's name=abc</code> works fine.</p>
  
  <p>But most of our conditions work on negation, such as <code>user's name=xyz and trip's name=abc and trip's name != def</code> doesn't work as expected.</p>
  
  <p>We are trying to find people who have gone on ABC trip, but not on DEF trip.  But the SQL generated for the above query generates this clause: <code>WHERE (trips.name LIKE 'ABC') AND (trips.name NOT LIKE 'DEF')</code>.  This obviously doesn't work as the users table is left-inner-joined with this clause and the trip.ids are generated for rows with name like ABC and not like DEF.</p>
  
  <p>How does one do this using Ransack?</p>
  
  <p>UPDATE:</p>
  
  <p>If the search query is "Users who have gone on trip named 'ABC'", the SQL generated is fine:
  <code>SELECT DISTINCT users.* FROM users LEFT OUTER JOIN registrations ON registrations.user_id = users.id LEFT OUTER JOIN trips ON trips.id = registrations.batch_id WHERE (trips.name LIKE '%ABC%')</code></p>
  
  <p>If the search query is "Users who have gone on trips 'ABC' and 'DEF'", how does one do it?  I tried two different approaches:</p>
  
  <ol>
  <li>Two separate conditions with name = 'ABC' and name = 'DEF'.  This was done with "matches all".  The SQL gave 0 results (obviously) as this was generated:
  <code>SELECT DISTINCT users.* FROM users LEFT OUTER JOIN registrations ON registrations.user_id = users.id LEFT OUTER JOIN trips ON trips.id = registrations.batch_id WHERE ((trips.name LIKE '%ABC%' AND trips.name LIKE '%DEF%'))</code></li>
  <li>I tried "matches any" instead.  That gave this:
  <code>SELECT DISTINCT users.* FROM users LEFT OUTER JOIN registrations ON registrations.user_id = users.id LEFT OUTER JOIN trips ON trips.id = registrations.batch_id WHERE ((trips.name LIKE '%ABC%' OR trips.name LIKE '%DEF%'))</code></li>
  </ol>
  
  <p>The 2nd query results were those users who had either gone on ABC or DEF.</p>
  
  <p>To add to this, we wanted this query: "Users who have gone on ABC but not on DEF".  I tried this with two conditions (matches all): trip.name = ABC and trips.name not like DEF.  This was the SQL generated:
  <code>SELECT DISTINCT users.* FROM users LEFT OUTER JOIN registrations ON registrations.user_id = users.id LEFT OUTER JOIN trips ON trips.id = registrations.batch_id WHERE ((trips.name LIKE '%ABC%' AND trips.name NOT LIKE '%DEF%'))</code></p>
  
  <p>The above query returned people who had gone on trip ABC.  It didn't filter out people who had done DEF as the query is obviously wrong.</p>