ActiveRecord find_each combined with limit and order

后端 未结 13 2113
温柔的废话
温柔的废话 2020-12-02 11:41

I\'m trying to run a query of about 50,000 records using ActiveRecord\'s find_each method, but it seems to be ignoring my other parameters like so:



        
13条回答
  •  隐瞒了意图╮
    2020-12-02 12:43

    As remarked by @Kirk in one of the comments, find_each supports limit as of version 5.1.0.

    Example from the changelog:

    Post.limit(10_000).find_each do |post|
      # ...
    end
    

    The documentation says:

    Limits are honored, and if present there is no requirement for the batch size: it can be less than, equal to, or greater than the limit.

    (setting a custom order is still not supported though)

提交回复
热议问题