【问题标题】:Are there any alternative ways for find_each method?find_each 方法有其他替代方法吗?
【发布时间】:2020-10-26 14:28:42
【问题描述】:

我一直在使用 Rails 2.3.5。
我想使用 find_each 方法,但版本中没有。

有没有其他方法可以为 Active Record 使用 find_each 方法?

【问题讨论】:

    标签: activerecord ruby-on-rails-2


    【解决方案1】:

    尝试使用 find_in_batches:

    Model.find_in_batches(:batch_size => 1000)  do |records|
        records.each { |record| <your logic here> }
    end
    

    【讨论】:

    • 感谢您告诉我。我可以做我想做的事。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-20
    • 2018-10-09
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多