mirror of https://github.com/rails/rails
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:
commit
9b6008924d
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue