提交 a0946692 编写于 作者: S Sebastian Martinez

Update AR querying guide with #first! and #last! new methods

上级 3b91b372
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册