mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Correct typos in "Active Record Query Interface" guide
This commit is contained in:
parent
044baef101
commit
2657ec8973
1 changed files with 19 additions and 19 deletions
|
@ -153,9 +153,9 @@ You can pass in a numerical argument to the `take` method to return up to that n
|
|||
```ruby
|
||||
client = Client.take(2)
|
||||
# => [
|
||||
#<Client id: 1, first_name: "Lifo">,
|
||||
#<Client id: 220, first_name: "Sara">
|
||||
]
|
||||
# #<Client id: 1, first_name: "Lifo">,
|
||||
# #<Client id: 220, first_name: "Sara">
|
||||
# ]
|
||||
```
|
||||
|
||||
The SQL equivalent of the above is:
|
||||
|
@ -192,10 +192,10 @@ You can pass in a numerical argument to the `first` method to return up to that
|
|||
```ruby
|
||||
client = Client.first(3)
|
||||
# => [
|
||||
#<Client id: 1, first_name: "Lifo">,
|
||||
#<Client id: 2, first_name: "Fifo">,
|
||||
#<Client id: 3, first_name: "Filo">
|
||||
]
|
||||
# #<Client id: 1, first_name: "Lifo">,
|
||||
# #<Client id: 2, first_name: "Fifo">,
|
||||
# #<Client id: 3, first_name: "Filo">
|
||||
# ]
|
||||
```
|
||||
|
||||
The SQL equivalent of the above is:
|
||||
|
@ -243,10 +243,10 @@ You can pass in a numerical argument to the `last` method to return up to that n
|
|||
```ruby
|
||||
client = Client.last(3)
|
||||
# => [
|
||||
#<Client id: 219, first_name: "James">,
|
||||
#<Client id: 220, first_name: "Sara">,
|
||||
#<Client id: 221, first_name: "Russel">
|
||||
]
|
||||
# #<Client id: 219, first_name: "James">,
|
||||
# #<Client id: 220, first_name: "Sara">,
|
||||
# #<Client id: 221, first_name: "Russel">
|
||||
# ]
|
||||
```
|
||||
|
||||
The SQL equivalent of the above is:
|
||||
|
@ -1613,7 +1613,7 @@ now want the client named 'Nick':
|
|||
|
||||
```ruby
|
||||
nick = Client.find_or_initialize_by(first_name: 'Nick')
|
||||
# => <Client id: nil, first_name: "Nick", orders_count: 0, locked: true, created_at: "2011-08-30 06:09:27", updated_at: "2011-08-30 06:09:27">
|
||||
# => #<Client id: nil, first_name: "Nick", orders_count: 0, locked: true, created_at: "2011-08-30 06:09:27", updated_at: "2011-08-30 06:09:27">
|
||||
|
||||
nick.persisted?
|
||||
# => false
|
||||
|
@ -1645,10 +1645,10 @@ Client.find_by_sql("SELECT * FROM clients
|
|||
INNER JOIN orders ON clients.id = orders.client_id
|
||||
ORDER BY clients.created_at desc")
|
||||
# => [
|
||||
#<Client id: 1, first_name: "Lucas" >,
|
||||
#<Client id: 2, first_name: "Jan" >,
|
||||
# ...
|
||||
]
|
||||
# #<Client id: 1, first_name: "Lucas" >,
|
||||
# #<Client id: 2, first_name: "Jan" >,
|
||||
# ...
|
||||
# ]
|
||||
```
|
||||
|
||||
`find_by_sql` provides you with a simple way of making custom calls to the database and retrieving instantiated objects.
|
||||
|
@ -1660,9 +1660,9 @@ Client.find_by_sql("SELECT * FROM clients
|
|||
```ruby
|
||||
Client.connection.select_all("SELECT first_name, created_at FROM clients WHERE id = '1'")
|
||||
# => [
|
||||
{"first_name"=>"Rafael", "created_at"=>"2012-11-10 23:23:45.281189"},
|
||||
{"first_name"=>"Eileen", "created_at"=>"2013-12-09 11:22:35.221282"}
|
||||
]
|
||||
# {"first_name"=>"Rafael", "created_at"=>"2012-11-10 23:23:45.281189"},
|
||||
# {"first_name"=>"Eileen", "created_at"=>"2013-12-09 11:22:35.221282"}
|
||||
# ]
|
||||
```
|
||||
|
||||
### `pluck`
|
||||
|
|
Loading…
Reference in a new issue