Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i'm not sure you can.</p> <p>But </p> <pre><code>Model.where(:id =&gt; 1) </code></pre> <p>Should generate a prepared statement. Fragment string works differently, so you can generate exactly what you need, in custom cases.</p> <p>Edit :</p> <p>Try this, i'm not sure it works, i can' test for now, but it looks like what you need :</p> <pre><code> Client.where("created_at &gt;= :start_date AND created_at &lt;= :end_date", {:start_date =&gt; params[:start_date], :end_date =&gt; params[:end_date]}) </code></pre> <p>More here: <a href="http://guides.rubyonrails.org/active_record_querying.html#conditions" rel="nofollow">http://guides.rubyonrails.org/active_record_querying.html#conditions</a></p> <p>In the placeholder section. Moreover date range works in the array format :</p> <p>:date => date_begenning..date_end</p> <p>Edit 2 : indeed you can, but i seems where don't support building this by hand.</p> <p>You might build your prepared queries by hand :</p> <p><a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-exec_query" rel="nofollow">http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-exec_query</a></p> <pre><code>exec_query(sql, name = 'SQL', binds = []) </code></pre> <p>There is also a bind method on your relation.</p> <p>But both binds need that the value have a name method, they will crash if you give a fixnum, a hash, ect. I hadn't found any doc explaining how this works.</p> <p>Bu for the where clause, as long it is of Class String, active ecord apply a .to_sql on it, so you don't get your prepared statement.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload