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

Merge pull request #18471 from ahmad-alkheat/master

Added the SQL equivalent of the find_by method. [ci skip]
This commit is contained in:
Rafael Mendonça França 2015-01-13 13:20:08 -02:00
commit 233029e90c

View file

@ -257,6 +257,12 @@ It is equivalent to writing:
Client.where(first_name: 'Lifo').take
```
The SQL equivalent of the above is:
```sql
SELECT * FROM clients WHERE (clients.first_name = 'Lifo') LIMIT 1
```
The `find_by!` method behaves exactly like `find_by`, except that it will raise `ActiveRecord::RecordNotFound` if no matching record is found. For example:
```ruby