aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/alias_tracker.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-10-23 21:42:11 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-10-23 21:53:32 +0900
commit9fedd013475456dc9bdbf0be45a194cc5fc2566e (patch)
treea72e3998cb5216cca3c267ed203e2fb7267faafa /activerecord/lib/active_record/associations/alias_tracker.rb
parentf4d1aa5310284ebceb51970140fa08f6c8ea19b6 (diff)
downloadrails-9fedd013475456dc9bdbf0be45a194cc5fc2566e.tar.gz
rails-9fedd013475456dc9bdbf0be45a194cc5fc2566e.tar.bz2
rails-9fedd013475456dc9bdbf0be45a194cc5fc2566e.zip
Ensure associations doesn't table name collide with string joins
Currently we have no test for alias tracking with string joins. I've add test case for that to catch a future regression.
Diffstat (limited to 'activerecord/lib/active_record/associations/alias_tracker.rb')
-rw-r--r--activerecord/lib/active_record/associations/alias_tracker.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb
index a8d8ee268a..6bac5fd3f5 100644
--- a/activerecord/lib/active_record/associations/alias_tracker.rb
+++ b/activerecord/lib/active_record/associations/alias_tracker.rb
@@ -19,14 +19,16 @@ module ActiveRecord
end
def self.initial_count_for(connection, name, table_joins)
- # quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase
- quoted_name = connection.quote_table_name(name).downcase
+ quoted_name = nil
counts = table_joins.map do |join|
if join.is_a?(Arel::Nodes::StringJoin)
+ # quoted_name should be case ignored as some database adapters (Oracle) return quoted name in uppercase
+ quoted_name ||= connection.quote_table_name(name)
+
# Table names + table aliases
- join.left.downcase.scan(
- /join(?:\s+\w+)?\s+(\S+\s+)?#{quoted_name}\son/
+ join.left.scan(
+ /JOIN(?:\s+\w+)?\s+(?:\S+\s+)?(?:#{quoted_name}|#{name})\sON/i
).size
elsif join.respond_to? :left
join.left.table_name == name ? 1 : 0