diff options
author | Xavier Noria <fxn@hashref.com> | 2011-03-25 23:47:57 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-03-25 23:47:57 +0100 |
commit | 6383f6704f5eca0d9094840fae2685f361b0e752 (patch) | |
tree | fc9a613eb1447367ff05826e5dc7c805ce8d8efa /railties | |
parent | 25be204e3c2c46b4eb7738daa0ac622738aa211b (diff) | |
parent | a0946692c13b7d1724cbc86731f3611a7f8177d2 (diff) | |
download | rails-6383f6704f5eca0d9094840fae2685f361b0e752.tar.gz rails-6383f6704f5eca0d9094840fae2685f361b0e752.tar.bz2 rails-6383f6704f5eca0d9094840fae2685f361b0e752.zip |
Merge branch 'master' of git://github.com/lifo/docrails
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 34 |
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 |