title: Ransacker predicate for multiple associations
body: <p>I have a case where I have a model called Event which:
   * has_one primary_day
   * has_one backup_day
   * has_one emergency_day</p>
  
  <p>In each of the has_one associations there a group of boolean fields that are the same e.g. 
  approved_legal,approved_malfunction,approved_costs etc</p>
  
  <p>In my search form - I don't want to search each association individually for those same fields.</p>
  
  <p>e.g I don't want to do this:</p>
  
  <pre><code>&lt;%= f.check_box :primary_day_approved_legal_true %&gt;
  </code></pre>
  
  <p>for each of the fields as it's too verbose instead I want to do this:</p>
  
  <pre><code>&lt;%= f.check_box :approved_legal_true %&gt; 
  </code></pre>
  
  <p>which will collate all the associations and return Events that have approved_legal true across all the has_one associations.</p>
  
  <p>I have tried a few different approaches to solving this but I can't get it to work so I assume that what I want to do is currently not possible. Could you confirm my theory or let me know how it could be achieved if it is indeed possible?</p>
  
  <p>For reference I have tried the following:</p>
  
  <h3>1. custom ransacker in the Event model</h3>
  
  <p>Since I'm happy to use the existing true predicate I thought just adding in a ransacker that returned what I wanted would be possible. But it seems not e.g. </p>
  
  <pre><code>ransacker :created_at do |parent|
    Arel.sql('select * from events inner join on primary_days .......')
  end
  </code></pre>
  
  <p>this ransacker seems to alway start with a select on the Model it was added to. So I cannot use a join to the associations. It seems the ransacker must return an existing database column on the model it's related to. So for the same reason there was not Arel code I could come up with that would make this approach work. Despite trying to create an Arel table to represent the associations and then trying to do the join in arel - but the result was always the same - no such method eq on ArelSelectManager.</p>
  
  <p>e.g </p>
  
  <pre><code>ransacker :created_at do |parent|
    primary_days = Arel::Table.new(:primary_days)
    events = parent.table
    events.join(primary_days).on(events[:id].eq(primary_days[:event_id]))
  end
  </code></pre>
  
  <h3>2. Using a named scope with a patch for scopes found in issue 61 - <a href="https://gist.github.com/RohanM/5350768" rel="nofollow">https://gist.github.com/RohanM/5350768</a></h3>
  
  <p>I put the code in the initializers/ransack.rb and then:</p>
  
  <p>Model:</p>
  
  <pre><code>scope_ransackable :approved_legal
  scope :approved_legal_scope, -&gt; { 
    Event.joins(:primary_day).where(:primary_days: {approved_legal: true}) 
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>Event.search_with_scopes(params[q])
  </code></pre>
  
  <p>View</p>
  
  <pre><code>&lt;%= f.check_box(:approved_legal_scope)%&gt;
  </code></pre>
  
  <p>But this just resulted in an error saying that approved_legal_scope method was not found on Ransack Search object</p>
  
  <p>Any pointer in the right direction would be very much appreciated. Thanks.</p>