Hi,

`find_each` depends on sequential ids to query for batches. It does this to
get batches:
```
2.0.0-p353 :024 > Catalog.find_each { }
  Catalog Load (4.3ms)  SELECT `catalogs`.* FROM `catalogs` ORDER BY
`catalogs`.`id` ASC LIMIT 1000
  Catalog Load (2.6ms)  SELECT `catalogs`.* FROM `catalogs` WHERE
(`catalogs`.`id` > 2088) ORDER BY `catalogs`.`id` ASC LIMIT 1000
  Catalog Load (2.4ms)  SELECT `catalogs`.* FROM `catalogs` WHERE
(`catalogs`.`id` > 3088) ORDER BY `catalogs`.`id` ASC LIMIT 1000
```

If you're ordering on something else there's no way to pick out subsequent
batches as the ids are not ordered.

You could use `OFFSET` and `LIMIT` but it's going to be hard on the
database.
Therefore the only safe and fast option is supported.



On Tue, Mar 4, 2014 at 11:34 AM, 亀田義裕 <[email protected]> wrote:

> This is a feature request.
>
>
> I can not use ActiveRecord::Batches#find_each to write huge csv because
> find_in_batch ignores order scope.
>
> find_in_batch's note say:
>
> # NOTE: It's not possible to set the order. That is automatically set to
> # ascending on the primary key ("id ASC") to make the batch ordering
> # work.
>
> OK.
> But I want to use this method to output csv too, because I want to cut
> memory space.
>
> I have an idea to solve this:
>
>    - find_each and find_by_batch method receive :use_order_scope option.
>
> How about this?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to