mirror of https://github.com/rails/rails
Merge pull request #50325 from fatkodima/fix-preloader-with-loaded-association-with-cpk
Fix `Preloader` to not generate a query for already loaded association with `query_constraints`
This commit is contained in:
commit
b02ebb30a8
|
@ -38,6 +38,8 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def load_records_for_keys(keys, &block)
|
||||
return [] if keys.empty?
|
||||
|
||||
if association_key_name.is_a?(Array)
|
||||
query_constraints = Hash.new { |hsh, key| hsh[key] = Set.new }
|
||||
|
||||
|
|
|
@ -1388,6 +1388,15 @@ class PreloaderTest < ActiveRecord::TestCase
|
|||
assert_equal sharded_blog_posts(:great_post_blog_one), comment.blog_post
|
||||
end
|
||||
|
||||
def test_preload_loaded_belongs_to_association_with_composite_foreign_key
|
||||
comment = sharded_comments(:great_comment_blog_post_one)
|
||||
comment.blog_post
|
||||
|
||||
assert_no_queries do
|
||||
ActiveRecord::Associations::Preloader.new(records: [comment], associations: :blog_post).call
|
||||
end
|
||||
end
|
||||
|
||||
def test_preload_has_many_through_association_with_composite_query_constraints
|
||||
tag = sharded_tags(:short_read_blog_one)
|
||||
|
||||
|
|
Loading…
Reference in New Issue