[ci skip] Consolidate docs for find_by

Since `find_by!` behaves exactly the same way but can raise an argument we can consolidate it in the `find_by` section.
This commit is contained in:
schneems 2014-06-28 14:07:25 -05:00
parent caa25e9fc3
commit 7d9c3ff55c

@ -185,7 +185,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
#### `find_by`
`Model.find_by` finds the first record matching some conditions. For example:
The `find_by` method finds the first record matching some conditions. For example:
```ruby
Client.find_by first_name: 'Lifo'
@ -201,6 +201,19 @@ It is equivalent to writing:
Client.where(first_name: 'Lifo').take
```
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
Client.find_by! first_name: 'does not exist'
# => ActiveRecord::RecordNotFound
```
This is equivalent to writing:
```ruby
Client.where(first_name: 'does not exist').take!
```
#### `take!`
`Model.take!` retrieves a record without any implicit ordering. For example:
@ -235,24 +248,6 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
`Model.last!` raises `ActiveRecord::RecordNotFound` if no matching record is found.
#### `find_by!`
`Model.find_by!` finds the first record matching some conditions. It raises `ActiveRecord::RecordNotFound` if no matching record is found. For example:
```ruby
Client.find_by! first_name: 'Lifo'
# => #<Client id: 1, first_name: "Lifo">
Client.find_by! first_name: 'Jon'
# => ActiveRecord::RecordNotFound
```
It is equivalent to writing:
```ruby
Client.where(first_name: 'Lifo').take!
```
### Retrieving Multiple Objects
#### Using Multiple Primary Keys