Skip to content

Commit

Permalink
Active Record v7 changed the way preloader works
Browse files Browse the repository at this point in the history
  • Loading branch information
rzane committed Jun 14, 2022
1 parent 8c5dcea commit 42660ce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/graphql/extras/preload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ def initialize(preload)
end

def fetch(records)
preloader = ActiveRecord::Associations::Preloader.new
preloader.preload(records, @preload)
if ActiveRecord::VERSION::MAJOR >= 7
preloader = ActiveRecord::Associations::Preloader.new(
records: records,
associations: @preload
)
preloader.call
else
preloader = ActiveRecord::Associations::Preloader.new
preloader.preload(records, @preload)
end

records
end
end
Expand Down

0 comments on commit 42660ce

Please sign in to comment.