Skip to content

Commit

Permalink
Don't store all aliases to a table
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgrif committed Sep 13, 2016
1 parent 4e0ce3d commit 44d2ef9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
8 changes: 2 additions & 6 deletions lib/arel/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ class Table
@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

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
Expand All @@ -27,9 +26,7 @@ def initialize(name, as: nil, type_caster: nil)
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
Expand Down Expand Up @@ -94,7 +91,6 @@ def hash
def eql? other
self.class == other.class &&
self.name == other.name &&
self.aliases == other.aliases &&
self.table_alias == other.table_alias
end
alias :== :eql?
Expand Down
9 changes: 1 addition & 8 deletions test/test_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,22 +188,18 @@ 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
end

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
Expand Down

0 comments on commit 44d2ef9

Please sign in to comment.