Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/lifo/docrails
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Mar 25, 2011
2 parents 25be204 + a094669 commit 6383f67
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions railties/guides/source/active_record_querying.textile
Expand Up @@ -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
Expand Down

0 comments on commit 6383f67

Please sign in to comment.