lib/gizzard/base.rb in gizzard-0.4.0 vs lib/gizzard/base.rb in gizzard-0.5.0
- old
+ new
@@ -1,9 +1,18 @@
module Gizzard
module Base
extend ActiveSupport::Concern
class_methods do
+ def delete_all_by_id(batch_size: 1000)
+ ids = pluck(:id)
+ ids.sort!
+ ids.each_slice(batch_size) do |chunked_ids|
+ # unscoped入れないと既に適用されているスコープが引き継がれる
+ unscoped.all.where(id: chunked_ids).delete_all
+ end
+ end
+
def less_than_id(id)
less_than(:id, id)
end
def greater_than_id(id)