1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't store all aliases to a table

The aliases property of a table is never used other than for equality. However,
the aliases that have been created for a table aren't really something that
should affect whether a table is considered to be the same table or not. This
removal does not appear to have any affect within Active Record or within Arel.
This commit is contained in:
Sean Griffin 2016-09-13 14:06:17 -04:00
parent 4e0ce3d6a5
commit 44d2ef9623
2 changed files with 3 additions and 14 deletions

View file

@ -6,7 +6,7 @@ module Arel
@engine = nil @engine = nil
class << self; attr_accessor :engine; end class << self; attr_accessor :engine; end
attr_accessor :name, :aliases, :table_alias attr_accessor :name, :table_alias
# TableAlias and Table both have a #table_name which is the name of the underlying table # TableAlias and Table both have a #table_name which is the name of the underlying table
alias :table_name :name alias :table_name :name
@ -14,7 +14,6 @@ module Arel
def initialize(name, as: nil, type_caster: nil) def initialize(name, as: nil, type_caster: nil)
@name = name.to_s @name = name.to_s
@columns = nil @columns = nil
@aliases = []
@type_caster = type_caster @type_caster = type_caster
# Sometime AR sends an :as parameter to table, to let the table know # Sometime AR sends an :as parameter to table, to let the table know
@ -27,9 +26,7 @@ module Arel
end end
def alias name = "#{self.name}_2" def alias name = "#{self.name}_2"
Nodes::TableAlias.new(self, name).tap do |node| Nodes::TableAlias.new(self, name)
@aliases << node
end
end end
def from def from
@ -94,7 +91,6 @@ module Arel
def eql? other def eql? other
self.class == other.class && self.class == other.class &&
self.name == other.name && self.name == other.name &&
self.aliases == other.aliases &&
self.table_alias == other.table_alias self.table_alias == other.table_alias
end end
alias :== :eql? alias :== :eql?

View file

@ -110,10 +110,7 @@ module Arel
describe 'alias' do describe 'alias' do
it 'should create a node that proxies to a table' do it 'should create a node that proxies to a table' do
@relation.aliases.must_equal []
node = @relation.alias node = @relation.alias
@relation.aliases.must_equal [node]
node.name.must_equal 'users_2' node.name.must_equal 'users_2'
node[:id].relation.must_equal node node[:id].relation.must_equal node
end end
@ -191,10 +188,8 @@ module Arel
describe 'equality' do describe 'equality' do
it 'is equal with equal ivars' do it 'is equal with equal ivars' do
relation1 = Table.new(:users) relation1 = Table.new(:users)
relation1.aliases = %w[a b c]
relation1.table_alias = 'zomg' relation1.table_alias = 'zomg'
relation2 = Table.new(:users) relation2 = Table.new(:users)
relation2.aliases = %w[a b c]
relation2.table_alias = 'zomg' relation2.table_alias = 'zomg'
array = [relation1, relation2] array = [relation1, relation2]
assert_equal 1, array.uniq.size assert_equal 1, array.uniq.size
@ -202,11 +197,9 @@ module Arel
it 'is not equal with different ivars' do it 'is not equal with different ivars' do
relation1 = Table.new(:users) relation1 = Table.new(:users)
relation1.aliases = %w[a b c]
relation1.table_alias = 'zomg' relation1.table_alias = 'zomg'
relation2 = Table.new(:users) relation2 = Table.new(:users)
relation2.aliases = %w[x y z] relation2.table_alias = 'zomg2'
relation2.table_alias = 'zomg'
array = [relation1, relation2] array = [relation1, relation2]
assert_equal 2, array.uniq.size assert_equal 2, array.uniq.size
end end