Skip to content
This repository
Browse code

Updated finders guide based on: http://rails.lighthouseapp.com/projec…

  • Loading branch information...
commit 3e762e8a97d3dbb60e12f369d70f46e2b10e01a0 1 parent 2b94b34
Ryan Bigg authored November 21, 2008

Showing 1 changed file with 13 additions and 3 deletions. Show diff stats Hide diff stats

  1. 16  railties/doc/guides/source/finders.txt
16  railties/doc/guides/source/finders.txt
@@ -78,7 +78,7 @@ Note that if you pass in a list of numbers that the result will be returned as a
78 78
 
79 79
 NOTE: If +find(id)+ or +find([id1, id2])+ fails to find any records, it will raise a +RecordNotFound+ exception.
80 80
 
81  
-If you wanted to find the first Client object you would simply type +Client.first+ and that would find the first client created in your clients table:
  81
+If you wanted to find the first Client object you would simply type +Client.first+ and that would find the first client in your clients table:
82 82
 
83 83
 -------------------------------------------------------
84 84
 >> Client.first
@@ -95,7 +95,7 @@ SELECT * FROM clients LIMIT 1
95 95
 
96 96
 Indicating the query that Rails has performed on your database. 
97 97
 
98  
-To find the last Client object you would simply type +Client.find(:last)+ and that would find the last client created in your clients table:
  98
+To find the last Client object you would simply type +Client.last+ and that would find the last client created in your clients table:
99 99
 
100 100
 -------------------------------------------------------
101 101
 >> Client.last
@@ -103,6 +103,15 @@ To find the last Client object you would simply type +Client.find(:last)+ and th
103 103
   created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">
104 104
 -------------------------------------------------------
105 105
 
  106
+If you were reading your log file (the default is log/development.log) you may see something like this:
  107
+
  108
+[source,sql]
  109
+-------------------------------------------------------
  110
+SELECT * FROM clients ORDER BY id DESC LIMIT 1
  111
+-------------------------------------------------------
  112
+
  113
+NOTE: Please be aware that the syntax that Rails uses to find the first record in the table means that it may not be the actual first record. If you want the actual first record based on a field in your table (e.g. +created_at+) specify an order option in your find call. The last method call works differently: it finds the last record on your table based on the primary key column.
  114
+
106 115
 [source,sql]
107 116
 -------------------------------------------------------
108 117
 SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
@@ -658,7 +667,8 @@ Thanks to Mike Gunderloy for his tips on creating this guide.
658 667
 
659 668
 http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16[Lighthouse ticket]
660 669
 
661  
-* Wednesday 16 2008: Fixed all points specified in http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16-activerecord-finders#ticket-16-11[this comment]
  670
+* November 21 2008: Fixed all points specified in http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16-activerecord-finders#ticket-16-13[this comment] and http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16-activerecord-finders#ticket-16-14[this comment]
  671
+* November 18 2008: Fixed all points specified in http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16-activerecord-finders#ticket-16-11[this comment]
662 672
 * November 8, 2008: Editing pass by link:../authors.html#mgunderloy[Mike Gunderloy] . First release version.
663 673
 * October 27, 2008: Added scoped section, added named params for conditions and added sub-section headers for conditions section by Ryan Bigg
664 674
 * October 27, 2008: Fixed up all points specified in http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16-activerecord-finders#ticket-16-6[this comment] with an exception of the final point by Ryan Bigg

0 notes on commit 3e762e8

Please sign in to comment.
Something went wrong with that request. Please try again.