title: Using Paginate with constructed query in active record
body: <p>I'm trying to do something along the following lines:</p>
  
  <pre><code>if start_date?
    query = where("datetime &gt; :start_date", :start_date =&gt; start_date)
  end
  
  if end_date?
    query = where("datetime &lt;= :end_date", :end_date =&gt; end_date)
  end
  
  if client
    query = where("client.name LIKE :client", :client =&gt; client)
  end
  
  if staff
    query = where("staff.name LIKE :staff", :staff =&gt; staff)
  end
  
  paginate :per_page =&gt; 20, :page =&gt; page,
             :conditions =&gt; query,
             :order =&gt; 'datetime'
  </code></pre>
  
  <p>I can't find any examples though of how to build up a query and use it along with paginate plugin. Of course the query isn't correct yet as I've got to figure out how to do the joins so I can query against the other properties in other tables, but other than that, how do you build up queries to use in the conditions?</p>