1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge branch 'master' of git://github.com/lifo/docrails

This commit is contained in:
Xavier Noria 2011-03-25 23:47:57 +01:00
commit 6383f6704f

View file

@ -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