lib/gizzard/base.rb in gizzard-0.6.1 vs lib/gizzard/base.rb in gizzard-0.7.0
- old
+ new
@@ -1,9 +1,17 @@
module Gizzard
module Base
extend ActiveSupport::Concern
class_methods do
+ def preload_associations(records:, associations:, scope: nil)
+ if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new(7)
+ ActiveRecord::Associations::Preloader.new(records: records, associations: associations, scope: scope).call
+ else
+ ActiveRecord::Associations::Preloader.new.preload(records, associations, scope)
+ end
+ end
+
def delete_all_by_id(batch_size: 1000)
ids = pluck(:id)
ids.sort!
ids.each_slice(batch_size) do |chunked_ids|
# unscoped入れないと既に適用されているスコープが引き継がれる