aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_record_querying.textile
diff options
context:
space:
mode:
authorSebastian Martinez <sebastian@wyeworks.com>2011-03-25 19:34:45 -0300
committerSebastian Martinez <sebastian@wyeworks.com>2011-03-25 19:34:45 -0300
commita0946692c13b7d1724cbc86731f3611a7f8177d2 (patch)
tree58a570a5255ea8f7eea645c648fb3e52ee010f4d /railties/guides/source/active_record_querying.textile
parent3b91b3726dbd7ef6e1f4927d65e2cbe8da12f7c7 (diff)
downloadrails-a0946692c13b7d1724cbc86731f3611a7f8177d2.tar.gz
rails-a0946692c13b7d1724cbc86731f3611a7f8177d2.tar.bz2
rails-a0946692c13b7d1724cbc86731f3611a7f8177d2.zip
Update AR querying guide with #first! and #last! new methods
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r--railties/guides/source/active_record_querying.textile34
1 files changed, 34 insertions, 0 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 009d541106..484ba796bd 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -130,6 +130,40 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
<tt>Model.last</tt> returns +nil+ if no matching record is found. No exception will be raised.
+h5. +first!+
+
+<tt>Model.first!</tt> finds the first record matched by the supplied options. For example:
+
+<ruby>
+client = Client.first!
+=> #<Client id: 1, first_name: "Lifo">
+</ruby>
+
+SQL equivalent of the above is:
+
+<sql>
+SELECT * FROM clients LIMIT 1
+</sql>
+
+<tt>Model.first!</tt> raises +RecordNotFound+ if no matching record is found.
+
+h5. +last!+
+
+<tt>Model.last!</tt> finds the last record matched by the supplied options. For example:
+
+<ruby>
+client = Client.last!
+=> #<Client id: 221, first_name: "Russel">
+</ruby>
+
+SQL equivalent of the above is:
+
+<sql>
+SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
+</sql>
+
+<tt>Model.last!</tt> raises +RecordNotFound+ if no matching record is found.
+
h4. Retrieving Multiple Objects
h5. Using Multiple Primary Keys