aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_record_querying.textile
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2011-03-28 04:20:49 +0100
committerGonçalo Silva <goncalossilva@gmail.com>2011-03-28 04:20:49 +0100
commit6f0caa1a534a065753d51430b649114bc8bf54ac (patch)
treeaf9657373436a38ef7828b26a804d1fe12e479ad /railties/guides/source/active_record_querying.textile
parent726b7ede54031eecfcee34eec80040553e9ad19f (diff)
parent245542ea2994961731be105db6c076256a22a7a9 (diff)
downloadrails-6f0caa1a534a065753d51430b649114bc8bf54ac.tar.gz
rails-6f0caa1a534a065753d51430b649114bc8bf54ac.tar.bz2
rails-6f0caa1a534a065753d51430b649114bc8bf54ac.zip
Merge branch 'master' of https://github.com/rails/rails into performance_test
Diffstat (limited to 'railties/guides/source/active_record_querying.textile')
-rw-r--r--railties/guides/source/active_record_querying.textile36
1 files changed, 35 insertions, 1 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile
index 009d541106..2c5d9e67e3 100644
--- a/railties/guides/source/active_record_querying.textile
+++ b/railties/guides/source/active_record_querying.textile
@@ -76,7 +76,7 @@ Primary operation of <tt>Model.find(options)</tt> can be summarized as:
h4. Retrieving a Single Object
-Active Record lets you retrieve a single object using three different ways.
+Active Record lets you retrieve a single object using five different ways.
h5. Using a Primary Key
@@ -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. 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. 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