From a85530820426f8baa4dbb1fa863313c6a6c69484 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 4 Mar 2011 06:13:22 +0800 Subject: 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). --- test/test_table.rb | 4 ++++ test/visitors/test_to_sql.rb | 9 +++++++++ 2 files changed, 13 insertions(+) (limited to 'test') diff --git a/test/test_table.rb b/test/test_table.rb index 129d7ba736..1035540513 100644 --- a/test/test_table.rb +++ b/test/test_table.rb @@ -164,6 +164,10 @@ module Arel @relation.name.must_equal 'users' end + it "should have a table name" do + @relation.table_name.must_equal 'users' + end + it "should have an engine" do @relation.engine.must_equal Table.engine end diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index c8ad40e242..2d5549ca43 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -259,6 +259,15 @@ module Arel } end end + + describe 'TableAlias' do + it "should use the underlying table for checking columns" do + test = Table.new(:users).alias('zomgusers')[:id].eq '3' + @visitor.accept(test).must_be_like %{ + "zomgusers"."id" = 3 + } + end + end end end end -- cgit v1.2.3