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:
parent
4e0ce3d6a5
commit
44d2ef9623
2 changed files with 3 additions and 14 deletions
|
@ -6,7 +6,7 @@ module Arel
|
|||
@engine = nil
|
||||
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
|
||||
alias :table_name :name
|
||||
|
@ -14,7 +14,6 @@ module Arel
|
|||
def initialize(name, as: nil, type_caster: nil)
|
||||
@name = name.to_s
|
||||
@columns = nil
|
||||
@aliases = []
|
||||
@type_caster = type_caster
|
||||
|
||||
# Sometime AR sends an :as parameter to table, to let the table know
|
||||
|
@ -27,9 +26,7 @@ module Arel
|
|||
end
|
||||
|
||||
def alias name = "#{self.name}_2"
|
||||
Nodes::TableAlias.new(self, name).tap do |node|
|
||||
@aliases << node
|
||||
end
|
||||
Nodes::TableAlias.new(self, name)
|
||||
end
|
||||
|
||||
def from
|
||||
|
@ -94,7 +91,6 @@ module Arel
|
|||
def eql? other
|
||||
self.class == other.class &&
|
||||
self.name == other.name &&
|
||||
self.aliases == other.aliases &&
|
||||
self.table_alias == other.table_alias
|
||||
end
|
||||
alias :== :eql?
|
||||
|
|
|
@ -110,10 +110,7 @@ module Arel
|
|||
|
||||
describe 'alias' do
|
||||
it 'should create a node that proxies to a table' do
|
||||
@relation.aliases.must_equal []
|
||||
|
||||
node = @relation.alias
|
||||
@relation.aliases.must_equal [node]
|
||||
node.name.must_equal 'users_2'
|
||||
node[:id].relation.must_equal node
|
||||
end
|
||||
|
@ -191,10 +188,8 @@ module Arel
|
|||
describe 'equality' do
|
||||
it 'is equal with equal ivars' do
|
||||
relation1 = Table.new(:users)
|
||||
relation1.aliases = %w[a b c]
|
||||
relation1.table_alias = 'zomg'
|
||||
relation2 = Table.new(:users)
|
||||
relation2.aliases = %w[a b c]
|
||||
relation2.table_alias = 'zomg'
|
||||
array = [relation1, relation2]
|
||||
assert_equal 1, array.uniq.size
|
||||
|
@ -202,11 +197,9 @@ module Arel
|
|||
|
||||
it 'is not equal with different ivars' do
|
||||
relation1 = Table.new(:users)
|
||||
relation1.aliases = %w[a b c]
|
||||
relation1.table_alias = 'zomg'
|
||||
relation2 = Table.new(:users)
|
||||
relation2.aliases = %w[x y z]
|
||||
relation2.table_alias = 'zomg'
|
||||
relation2.table_alias = 'zomg2'
|
||||
array = [relation1, relation2]
|
||||
assert_equal 2, array.uniq.size
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue