diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-13 18:12:59 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-13 18:12:59 +0000 |
commit | ff1db4de5f291baef70ba637101bed35d79c4b86 (patch) | |
tree | 91b7c25b59c6f067273031c8bd5705c30dc86bd8 /activerecord | |
parent | 71bdf13b60bb8ac6a06f05eea94399bf9de27a92 (diff) | |
download | rails-ff1db4de5f291baef70ba637101bed35d79c4b86.tar.gz rails-ff1db4de5f291baef70ba637101bed35d79c4b86.tar.bz2 rails-ff1db4de5f291baef70ba637101bed35d79c4b86.zip |
Qualify the ids used such that eager loading can avoid ambigious keys
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1163 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
4 files changed, 6 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 85f4122138..af93b5c152 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -156,7 +156,7 @@ module ActiveRecord "j.#{@association_class_primary_key_name} = #{@owner.quoted_id} " @finder_sql << " AND #{interpolate_sql(@options[:conditions])}" if @options[:conditions] - @finder_sql << "ORDER BY #{@order}" if @order + @finder_sql << " ORDER BY #{@order}" if @order end end end diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 272a1fe567..4a9d773ac7 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -112,7 +112,7 @@ module ActiveRecord else ids = quoted_record_ids(records) @association_class.update_all( - "#{@association_class_primary_key_name} = NULL", + "#{@association_class.table_name}.#{@association_class_primary_key_name} = NULL", "#{@association_class_primary_key_name} = #{@owner.quoted_id} AND #{@association_class.primary_key} IN (#{ids})" ) end @@ -126,7 +126,7 @@ module ActiveRecord if @options[:finder_sql] @finder_sql = interpolate_sql(@options[:finder_sql]) else - @finder_sql = "#{@association_class_primary_key_name} = #{@owner.quoted_id}" + @finder_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}" @finder_sql << " AND #{interpolate_sql(@conditions)}" if @conditions end @@ -136,7 +136,7 @@ module ActiveRecord @options[:counter_sql] = @options[:finder_sql].gsub(/SELECT (.*) FROM/i, "SELECT COUNT(*) FROM") @counter_sql = interpolate_sql(@options[:counter_sql]) else - @counter_sql = "#{@association_class_primary_key_name} = #{@owner.quoted_id}" + @counter_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}" @counter_sql << " AND #{interpolate_sql(@conditions)}" if @conditions end end diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index f3c3515055..d917f0a799 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -46,7 +46,7 @@ module ActiveRecord end def construct_sql - @finder_sql = "#{@association_class_primary_key_name} = #{@owner.quoted_id}#{@options[:conditions] ? " AND " + @options[:conditions] : ""}" + @finder_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}#{@options[:conditions] ? " AND " + @options[:conditions] : ""}" end end end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 841940897a..1daed0e3a1 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -737,7 +737,7 @@ module ActiveRecord #:nodoc: condition << "OR #{table_name}.#{inheritance_column} = '#{subclass.name.demodulize}' " end - return " (#{type_condition})" + return " (#{type_condition}) " end # Guesses the table name, but does not decorate it with prefix and suffix information. |