Skip to content

Commit

Permalink
Array conditions dont need []
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo authored and fxn committed Aug 31, 2010
1 parent 6655a3c commit 9017e1f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions railties/guides/source/active_record_querying.textile
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,23 @@ h4. Array Conditions
Now what if that number could vary, say as an argument from somewhere, or perhaps from the user's level status somewhere? The find then becomes something like:

<ruby>
Client.where(["orders_count = ?", params[:orders]])
Client.where("orders_count = ?", params[:orders])
</ruby>

Active Record will go through the first element in the conditions value and any additional elements will replace the question marks +(?)+ in the first element.

Or if you want to specify two conditions, you can do it like:

<ruby>
Client.where(["orders_count = ? AND locked = ?", params[:orders], false])
Client.where("orders_count = ? AND locked = ?", params[:orders], false)
</ruby>

In this example, the first question mark will be replaced with the value in +params[:orders]+ and the second will be replaced with the SQL representation of +false+, which depends on the adapter.

The reason for doing code like:

<ruby>
Client.where(["orders_count = ?", params[:orders]])
Client.where("orders_count = ?", params[:orders])
</ruby>

instead of:
Expand Down

0 comments on commit 9017e1f

Please sign in to comment.