Merge pull request #40749 from kamipo/dont_use_explicit_references_for_join_aliases

Don't use explicit references for join aliases
This commit is contained in:
Ryuta Kamizono 2020-12-04 17:24:27 +09:00 committed by GitHub
commit 9b6008924d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -84,7 +84,7 @@ module ActiveRecord
@references = {}
references.each do |table_name|
@references[table_name.to_sym] = table_name if table_name.is_a?(String)
@references[table_name.to_sym] = table_name if table_name.is_a?(Arel::Nodes::SqlLiteral)
end unless references.empty?
joins = make_join_constraints(join_root, join_type)

View File

@ -32,9 +32,9 @@ module ActiveRecord
def self.references(attributes)
attributes.each_with_object([]) do |(key, value), result|
if value.is_a?(Hash)
result << key
result << Arel.sql(key)
elsif key.include?(".")
result << key.split(".").first
result << Arel.sql(key.split(".").first)
end
end
end

View File

@ -663,10 +663,10 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
posts = Post.includes(:author, :comments).limit(2).references(:author).where("authors.name = ?", "David")
posts = Post.includes(:author, :comments).limit(2).references("author").where("authors.name = ?", "David")
assert_equal 2, posts.size
count = Post.includes(:author, :comments).limit(2).references(:author).where("authors.name = ?", "David").count
count = Post.includes(:author, :comments).limit(2).references("author").where("authors.name = ?", "David").count
assert_equal posts.size, count
end