aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-07 08:36:09 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-07 08:36:09 -0800
commit2fc53bec29bb660e501cf350ae07506082dcb110 (patch)
tree7cd8a27a81372589cf9c3c65c6f6e4904a521599 /lib/arel
parente7cdaedb6bc7d452142b9b8c42942d659efcd11a (diff)
parenta85530820426f8baa4dbb1fa863313c6a6c69484 (diff)
downloadrails-2fc53bec29bb660e501cf350ae07506082dcb110.tar.gz
rails-2fc53bec29bb660e501cf350ae07506082dcb110.tar.bz2
rails-2fc53bec29bb660e501cf350ae07506082dcb110.zip
Merge branch 'master' of github.com:rails/arel
* 'master' of github.com:rails/arel: Add an #table_name method to Table and TableAlias, which always returns the actual table name, not the alias. Then fix ToSql#column_for to use this table name when checking whether the table exists (rather than before, where it was checking whether a table with the alias name exists, which was incorrect).
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/nodes/table_alias.rb4
-rw-r--r--lib/arel/table.rb3
-rw-r--r--lib/arel/visitors/to_sql.rb2
3 files changed, 8 insertions, 1 deletions
diff --git a/lib/arel/nodes/table_alias.rb b/lib/arel/nodes/table_alias.rb
index 4f4d5e29e9..1d3d36be0c 100644
--- a/lib/arel/nodes/table_alias.rb
+++ b/lib/arel/nodes/table_alias.rb
@@ -8,6 +8,10 @@ module Arel
def [] name
Attribute.new(self, name)
end
+
+ def table_name
+ relation.name
+ end
end
end
end
diff --git a/lib/arel/table.rb b/lib/arel/table.rb
index d1d1e40e11..2aff71b220 100644
--- a/lib/arel/table.rb
+++ b/lib/arel/table.rb
@@ -8,6 +8,9 @@ module Arel
attr_accessor :name, :engine, :aliases, :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, engine = Table.engine
@name = name.to_s
@engine = engine
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 7eaaff8e13..f30557e509 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -88,7 +88,7 @@ key on UpdateManager using UpdateManager#key=
def column_for attr
name = attr.name.to_s
- table = attr.relation.name
+ table = attr.relation.table_name
return nil unless table_exists? table