@@ -356,7 +356,7 @@ Two additional options, `:batch_size` and `:start`, are available as well.
The `:batch_size` option allows you to specify the number of records to be retrieved in each batch, before being passed individually to the block. For example, to retrieve records in batches of 5000:
```ruby
User.find_each(:batch_size=>5000)do|user|
User.find_each(batch_size:5000)do|user|
NewsLetter.weekly_deliver(user)
end
```
...
...
@@ -368,7 +368,7 @@ By default, records are fetched in ascending order of the primary key, which mus
For example, to send newsletters only to users with the primary key starting from 2000, and to retrieve them in batches of 5000:
In the case of a belongs_to relationship, an association key can be used to specify the model if an ActiveRecord object is used as the value. This method works with polymorphic relationships as well.
This will find the category with id 1 and eager load all of the associated posts, the associated posts' tags and comments, and every comment's guest association.
...
...
@@ -1109,7 +1109,7 @@ Scopes are also chainable within scopes:
@@ -1278,7 +1278,7 @@ second time we run this code, the block will be ignored.
You can also use `find_or_create_by!` to raise an exception if the new record is invalid. Validations are not covered on this guide, but let's assume for a moment that you temporarily add
```ruby
validates:orders_count,:presence=>true
validates:orders_count,presence:true
```
to your `Client` model. If you try to create a new `Client` without passing an `orders_count`, the record will be invalid and an exception will be raised:
...
...
@@ -1346,7 +1346,7 @@ Client.connection.select_all("SELECT * FROM clients WHERE id = '1'")
`pluck` can be used to query a single or multiple columns from the underlying table of a model. It accepts a list of column names as argument and returns an array of values of the specified columns with the corresponding data type.
```ruby
Client.where(:active=>true).pluck(:id)
Client.where(active:true).pluck(:id)
# SELECT id FROM clients WHERE active = 1
# => [1, 2, 3]
...
...
@@ -1415,7 +1415,7 @@ Client.exists?([1,2,3])
It's even possible to use `exists?` without any arguments on a model or a relation.
```ruby
Client.where(:first_name=>'Ryan').exists?
Client.where(first_name:'Ryan').exists?
```
The above returns `true` if there is at least one client with the `first_name` 'Ryan' and `false` otherwise.
...
...
@@ -1438,8 +1438,8 @@ Post.recent.any?
Post.recent.many?
# via a relation
Post.where(:published=>true).any?
Post.where(:published=>true).many?
Post.where(published:true).any?
Post.where(published:true).many?
# via an association
Post.first.categories.any?
...
...
@@ -1461,14 +1461,14 @@ Client.count
Or on a relation:
```ruby
Client.where(:first_name=>'Ryan').count
Client.where(first_name:'Ryan').count
# SELECT count(*) AS count_all FROM clients WHERE (first_name = 'Ryan')
```
You can also use various finder methods on a relation for performing complex calculations: