title: How to implement nested filters in diesel?
body: <p>I'm quite new to Rust and Diesel. I'm now trying to implement Diesel filtering for query like this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>-- @param1 is duration in years
  -- @param2 is duration in months
  
  SELECT columns FROM a
  WHERE 
  (...dynamic AND clauses)
  AND (((a.min_unit = "Years") AND (a.min_duration &lt;= @param1))
    OR ((a.min_unit = "Months") AND (a.min_duration &lt;= @param2)))
  (...dynamic AND clauses)
  </code></pre>
  
  <p>After some searches in docs and around the web, I still couldn't find how to do this.
  My closest guess is:</p>
  
  <pre class="lang-rust prettyprint-override"><code>let param1 = ...;
  let param2 = ...;
  
  let mut query = a::table.select(a::all_columns).into_boxed();
  // dynamic clauses: query = query.filter(...) ...
  query = query.filter(a::min_unit.eq(Some("Years")).and(a::min_duration.le(Some(param1))))
    .or_filter(a::min_unit.eq(Some("Months")).and(a::min_duration.le(Some(param2))));
  // dynamic clauses: query = query.filter(...) ...
  
  let results = a::table.load&lt;A&gt;(&amp;*conn);
  </code></pre>
  
  <p>Anyone has idea?</p>
  
  <p>Thanks!</p>