Fixed up syntax errors.

This commit is contained in:
Ryan Bigg
2008-12-17 09:32:29 +10:30
parent 76f87802a2
commit fd117c52fa

View File

@@ -185,7 +185,7 @@ SELECT * FROM users WHERE (created_at IN
'2008-12-27','2008-12-28','2008-12-29','2008-12-30','2008-12-31'))
-------------------------------------------------------
Things can get *really* messy if you pass in time objects as it will attempt to compare your field to *every second* in that range:
Things can get *really* messy if you pass in Time objects as it will attempt to compare your field to *every second* in that range:
[source, ruby]
-------------------------------------------------------
@@ -224,7 +224,7 @@ Client.all(:conditions =>
["created_at >= ? AND created_at <= ?", params[:start_date], params[:end_date]])
-------------------------------------------------------
Just like in Ruby.
Just like in Ruby. If you want a shorter syntax be sure to check out the <<_hash_conditions, Hash Conditions>> section later on in the guide.
=== Placeholder Conditions ===
@@ -238,7 +238,7 @@ Client.all(:conditions =>
This makes for clearer readability if you have a large number of variable conditions.
=== Hash Conditions ==
=== Hash Conditions
Rails also allows you to pass in a hash conditions too which can increase the readability of your conditions syntax. With hash conditions, you pass in a hash with keys of the fields you want conditionalised and the values of how you want to conditionalise them:
@@ -261,7 +261,7 @@ The good thing about this is that we can pass in a range for our fields without
Client.all(:conditions => { :created_at => ((Time.now.midnight - 1.day)..Time.now.midnight})
-------------------------------------------------------
This will find all clients created yesterday.
This will find all clients created yesterday. This shows the shorter syntax for the examples in <<_array_conditions, Array Conditions>>
You can also join in tables and specify their columns in the hash:
@@ -653,7 +653,7 @@ This code specifies +clients.first_name+ just in case one of the join tables has
If you want to see how many records are in your model's table you could call +Client.count+ and that will return the number. If you want to be more specific and find all the clients with their age present in the database you can use +Client.count(:age)+.
For options, please see the parent section, Calculations.
For options, please see the parent section, <<_calculations, Calculations>>.
=== Average
@@ -666,7 +666,7 @@ Client.average("orders_count")
This will return a number (possibly a floating point number such as 3.14159265) representing the average value in the field.
For options, please see the parent section, <<_calculations, Calculations>>
For options, please see the parent section, <<_calculations, Calculations>>.
=== Minimum
@@ -711,6 +711,7 @@ Thanks to Mike Gunderloy for his tips on creating this guide.
http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16[Lighthouse ticket]
* December 17 2008: Fixed up syntax errors.
* December 16 2008: Covered hash conditions that were introduced in Rails 2.2.2.
* December 1 2008: Added using an SQL function example to Selecting Certain Fields section as per http://rails.lighthouseapp.com/projects/16213/tickets/36-adding-an-example-for-using-distinct-to-ar-finders[this ticket]
* November 23 2008: Added documentation for +find_by_last+ and +find_by_bang!+