From a83e6b1b6aa8ee67a47658ed27481e38aa2a62da Mon Sep 17 00:00:00 2001 From: Raimonds Simanovskis Date: Mon, 15 Feb 2010 00:38:29 +0200 Subject: downcase table names in aliased_table_name_for and references_eager_loaded_tables? methods (as Oracle quoted table names are in uppercase) --- activerecord/lib/active_record/relation.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 4e62187449..b6b4085ec0 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -356,13 +356,15 @@ module ActiveRecord end def references_eager_loaded_tables? - joined_tables = (tables_in_string(arel.joins(arel)) + [table.name, table.table_alias]).compact.uniq + # always convert table names to downcase as in Oracle quoted table names are in uppercase + joined_tables = (tables_in_string(arel.joins(arel)) + [table.name, table.table_alias]).compact.map(&:downcase).uniq (tables_in_string(to_sql) - joined_tables).any? end def tables_in_string(string) return [] if string.blank? - string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.uniq + # always convert table names to downcase as in Oracle quoted table names are in uppercase + string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.map(&:downcase).uniq end end -- cgit v1.2.3 From edf79a7fe7c78e291c06a6d8be3ae87dabde9afa Mon Sep 17 00:00:00 2001 From: Raimonds Simanovskis Date: Sun, 16 May 2010 20:26:40 +0300 Subject: Downcase quoted table name in regex in count_aliases_from_table_joins Oracle adapter's quote_table_name returns quoted table name in uppercase and therefore it should be downcased before scanning downcased join_sql --- activerecord/lib/active_record/associations.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 5b0ba86308..7d5fd8e96c 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1755,7 +1755,8 @@ module ActiveRecord end def count_aliases_from_table_joins(name) - quoted_name = join_base.active_record.connection.quote_table_name(name.downcase) + # quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase + quoted_name = join_base.active_record.connection.quote_table_name(name.downcase).downcase join_sql = join_base.table_joins.to_s.downcase join_sql.blank? ? 0 : # Table names -- cgit v1.2.3 From c51fa6bdfc202f78907a7d1cb6bce7b0e2562913 Mon Sep 17 00:00:00 2001 From: Raimonds Simanovskis Date: Mon, 17 May 2010 00:19:18 +0300 Subject: ignore raw_sql_ table alias that is used by Oracle adapter --- activerecord/lib/active_record/relation.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index b6b4085ec0..99c914d7fc 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -364,7 +364,8 @@ module ActiveRecord def tables_in_string(string) return [] if string.blank? # always convert table names to downcase as in Oracle quoted table names are in uppercase - string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.map(&:downcase).uniq + # ignore raw_sql_ that is used by Oracle adapter as alias for limit/offset subqueries + string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.map(&:downcase).uniq - ['raw_sql_'] end end -- cgit v1.2.3