diff options
author | eileencodes <eileencodes@gmail.com> | 2014-11-24 14:56:27 -0500 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2014-11-24 19:05:45 -0500 |
commit | 9e7037f19865021030893880b16be7b1ecbd3470 (patch) | |
tree | 2a57474e9efba48387e4815de1482e7e9640e1b9 /activerecord/lib/active_record/associations/alias_tracker.rb | |
parent | 35362fc2263d4d7784de172cb5f97eb2541fb65a (diff) | |
download | rails-9e7037f19865021030893880b16be7b1ecbd3470.tar.gz rails-9e7037f19865021030893880b16be7b1ecbd3470.tar.bz2 rails-9e7037f19865021030893880b16be7b1ecbd3470.zip |
Combine aliased_table_for and aliased_name_for
This refactoring reduces the number of conditionals needed to build
`aliased_table_for` and removes `aliased_name_for` because it's no
longer necessary.
`aliased_name_for` was also used in `JoinDependency#initialize` so
that was replaced with `aliased_table_for` as well.
Diffstat (limited to 'activerecord/lib/active_record/associations/alias_tracker.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/alias_tracker.rb | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb index a6a1947148..0c3234ed24 100644 --- a/activerecord/lib/active_record/associations/alias_tracker.rb +++ b/activerecord/lib/active_record/associations/alias_tracker.rb @@ -57,20 +57,10 @@ module ActiveRecord end def aliased_table_for(table_name, aliased_name) - table_alias = aliased_name_for(table_name, aliased_name) - - if table_alias == table_name - Arel::Table.new(table_name) - else - Arel::Table.new(table_name).alias(table_alias) - end - end - - def aliased_name_for(table_name, aliased_name) if aliases[table_name].zero? # If it's zero, we can have our table_name aliases[table_name] = 1 - table_name + Arel::Table.new(table_name) else # Otherwise, we need to use an alias aliased_name = connection.table_alias_for(aliased_name) @@ -78,11 +68,12 @@ module ActiveRecord # Update the count aliases[aliased_name] += 1 - if aliases[aliased_name] > 1 + table_alias = if aliases[aliased_name] > 1 "#{truncate(aliased_name)}_#{aliases[aliased_name]}" else aliased_name end + Arel::Table.new(table_name).alias(table_alias) end end |