Skip to content

Commit

Permalink
Preloader doesn't preload collection associations in rails 7.
Browse files Browse the repository at this point in the history
See: https://www.github.com/rails/rails/pull/42654

Note, Preloader and available records is a private API so it's not guaranteed
to work as it currently does, see:
https://www.github.com/rails/rails/issues/45804
  • Loading branch information
jrafanie committed Jun 21, 2024
1 parent 82a808e commit 1c5ab04
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/virtual_includes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,13 @@
end

it "preloads virtual_reflection(:uses => :books => :bookmarks) (nothing virtual)" do
skip "ActiveRecord Preloader doesn't preload collection associations in rails 7+. See: https://www.github.com/rails/rails/pull/42654" if ActiveRecord.version >= Gem::Version.new(7.0)
bookmarked_book = Author.first.books.first
expect(Author.includes(:book_with_most_bookmarks)).to preload_values(:book_with_most_bookmarks, bookmarked_book)
end

it "preloads virtual_reflection(:uses => :books => :bookmarks, :uses => :books) (multiple overlapping relations)" do
skip "ActiveRecord Preloader doesn't preload collection associations in rails 7+. See: https://www.github.com/rails/rails/pull/42654" if ActiveRecord.version >= Gem::Version.new(7.0)
bookmarked_book = Author.first.books.first
expect(Author.includes(:book_with_most_bookmarks, :books)).to preload_values(:book_with_most_bookmarks, bookmarked_book)
end
Expand Down Expand Up @@ -402,6 +404,7 @@
end

it "preloads virtual_reflection(:uses => :books => :bookmarks) (nothing virtual)" do
skip "ActiveRecord Preloader doesn't preload collection associations in rails 7+. See: https://www.github.com/rails/rails/pull/42654" if ActiveRecord.version >= Gem::Version.new(7.0)
bookmarked_book = Author.first.books.first
expect(preloaded(Author.all.to_a, :book_with_most_bookmarks)).to preload_values(:book_with_most_bookmarks, bookmarked_book)
end
Expand Down

0 comments on commit 1c5ab04

Please sign in to comment.