From 9a1a32ac2b8a526f543367bc7e8258bbd7e6a164 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sun, 31 Oct 2010 11:21:28 +0000 Subject: Fix naughty trailing whitespace --- .../active_record/associations/alias_tracker.rb | 26 ++++----- .../associations/has_many_through_association.rb | 4 +- .../associations/has_one_through_association.rb | 2 +- .../associations/through_association_scope.rb | 64 +++++++++++----------- 4 files changed, 48 insertions(+), 48 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb index 10e90ec117..64582188b6 100644 --- a/activerecord/lib/active_record/associations/alias_tracker.rb +++ b/activerecord/lib/active_record/associations/alias_tracker.rb @@ -11,10 +11,10 @@ module ActiveRecord @aliases = Hash.new @other_sql = other_sql.to_s.downcase end - + def aliased_name_for(table_name, aliased_name = nil) aliased_name ||= table_name - + initialize_count_for(table_name) if @aliases[table_name].nil? if @aliases[table_name].zero? @@ -24,12 +24,12 @@ module ActiveRecord else # Otherwise, we need to use an alias aliased_name = connection.table_alias_for(aliased_name) - + initialize_count_for(aliased_name) if @aliases[aliased_name].nil? - + # Update the count @aliases[aliased_name] += 1 - + if @aliases[aliased_name] > 1 "#{truncate(aliased_name)}_#{@aliases[aliased_name]}" else @@ -41,30 +41,30 @@ module ActiveRecord def pluralize(table_name) ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name end - + private - + def initialize_count_for(name) @aliases[name] = 0 - + unless @other_sql.blank? # quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase quoted_name = connection.quote_table_name(name.downcase).downcase - + # Table names @aliases[name] += @other_sql.scan(/join(?:\s+\w+)?\s+#{quoted_name}\son/).size - + # Table aliases @aliases[name] += @other_sql.scan(/join(?:\s+\w+)?\s+\S+\s+#{quoted_name}\son/).size end - + @aliases[name] end - + def truncate(name) name[0..connection.table_alias_length-3] end - + def connection ActiveRecord::Base.connection end diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 2c9fa3b447..c45f2ee224 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -66,7 +66,7 @@ module ActiveRecord def insert_record(record, force = true, validate = true) ensure_not_nested - + if record.new_record? if force record.save! @@ -83,7 +83,7 @@ module ActiveRecord # TODO - add dependent option support def delete_records(records) ensure_not_nested - + klass = @reflection.through_reflection.klass records.each do |associate| klass.delete_all(construct_join_attributes(associate)) diff --git a/activerecord/lib/active_record/associations/has_one_through_association.rb b/activerecord/lib/active_record/associations/has_one_through_association.rb index de962e01b6..e9dc32efd3 100644 --- a/activerecord/lib/active_record/associations/has_one_through_association.rb +++ b/activerecord/lib/active_record/associations/has_one_through_association.rb @@ -15,7 +15,7 @@ module ActiveRecord def create_through_record(new_value) #nodoc: ensure_not_nested - + klass = @reflection.through_reflection.klass current_object = @owner.send(@reflection.through_reflection.name) diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb index abe7af418d..07ce6f1597 100644 --- a/activerecord/lib/active_record/associations/through_association_scope.rb +++ b/activerecord/lib/active_record/associations/through_association_scope.rb @@ -18,7 +18,7 @@ module ActiveRecord :readonly => @reflection.options[:readonly] } end - + def construct_create_scope @reflection.nested? ? {} : construct_owner_attributes(@reflection) end @@ -26,18 +26,18 @@ module ActiveRecord # Build SQL conditions from attributes, qualified by table name. def construct_conditions reflection = @reflection.through_reflection_chain.last - + if reflection.macro == :has_and_belongs_to_many table_alias = table_aliases[reflection].first else table_alias = table_aliases[reflection] end - + parts = construct_quoted_owner_attributes(reflection).map do |attr, value| "#{table_alias}.#{attr} = #{value}" end parts += reflection_conditions(0) - + "(" + parts.join(') AND (') + ")" end @@ -59,18 +59,18 @@ module ActiveRecord distinct = "DISTINCT " if @reflection.options[:uniq] selected = custom_select || @reflection.options[:select] || "#{distinct}#{@reflection.quoted_table_name}.*" end - + def construct_joins(custom_joins = nil) "#{construct_through_joins} #{@reflection.options[:joins]} #{custom_joins}" end def construct_through_joins joins, right_index = [], 1 - + # Iterate over each pair in the through reflection chain, joining them together @reflection.through_reflection_chain.each_cons(2) do |left, right| right_table_and_alias = table_name_and_alias(right.quoted_table_name, table_aliases[right]) - + if left.source_reflection.nil? case left.macro when :belongs_to @@ -113,7 +113,7 @@ module ActiveRecord else right_table = table_aliases[right] end - + joins << inner_join_sql( right_table_and_alias, table_aliases[left], left.primary_key_name, @@ -121,7 +121,7 @@ module ActiveRecord polymorphic_conditions(left, left.source_reflection), reflection_conditions(right_index) ) - + if right.macro == :has_and_belongs_to_many joins << inner_join_sql( table_name_and_alias( @@ -134,7 +134,7 @@ module ActiveRecord end when :has_and_belongs_to_many join_table, left_table = table_aliases[left] - + joins << inner_join_sql( table_name_and_alias( quote_table_name(left.source_reflection.options[:join_table]), @@ -143,7 +143,7 @@ module ActiveRecord left_table, left.klass.primary_key, join_table, left.association_foreign_key ) - + joins << inner_join_sql( right_table_and_alias, join_table, left.primary_key_name, @@ -152,10 +152,10 @@ module ActiveRecord ) end end - + right_index += 1 end - + joins.join(" ") end @@ -170,77 +170,77 @@ module ActiveRecord reflection.table_name, table_alias_for(reflection, reflection != @reflection) )) - + if reflection.macro == :has_and_belongs_to_many || (reflection.source_reflection && reflection.source_reflection.macro == :has_and_belongs_to_many) - + join_table_alias = quote_table_name(alias_tracker.aliased_name_for( (reflection.source_reflection || reflection).options[:join_table], table_alias_for(reflection, true) )) - + aliases[reflection] = [join_table_alias, table_alias] else aliases[reflection] = table_alias end - + aliases end end end - + def table_alias_for(reflection, join = false) name = alias_tracker.pluralize(reflection.name) name << "_#{@reflection.name}" name << "_join" if join name end - + def quote_table_name(table_name) @reflection.klass.connection.quote_table_name(table_name) end - + def table_name_and_alias(table_name, table_alias) "#{table_name} #{table_alias if table_alias != table_name}".strip end - + def inner_join_sql(table, on_left_table, on_left_key, on_right_table, on_right_key, *conditions) conditions << "#{on_left_table}.#{on_left_key} = #{on_right_table}.#{on_right_key}" conditions = conditions.flatten.compact conditions = conditions.map { |sql| "(#{sql})" } * ' AND ' - + "INNER JOIN #{table} ON #{conditions}" end - + def reflection_conditions(index) reflection = @reflection.through_reflection_chain[index] reflection_conditions = @reflection.through_conditions[index] - + conditions = [] - + if reflection.options[:as].nil? && # reflection.klass is a Module if :as is used reflection.klass.finder_needs_type_condition? conditions << reflection.klass.send(:type_condition).to_sql end - + reflection_conditions.each do |condition| sanitized_condition = reflection.klass.send(:sanitize_sql, condition) interpolated_condition = interpolate_sql(sanitized_condition) - + if condition.is_a?(Hash) interpolated_condition.gsub!( @reflection.quoted_table_name, reflection.quoted_table_name ) end - + conditions << interpolated_condition end - + conditions end - + def polymorphic_conditions(reflection, polymorphic_reflection) if polymorphic_reflection.options[:as] "%s.%s = %s" % [ @@ -249,7 +249,7 @@ module ActiveRecord ] end end - + def source_type_conditions(reflection) if reflection.options[:source_type] "%s.%s = %s" % [ @@ -289,7 +289,7 @@ module ActiveRecord join_attributes end - + def ensure_not_nested if @reflection.nested? raise HasManyThroughNestedAssociationsAreReadonly.new(@owner, @reflection) -- cgit v1.2.3