support relations created with a table alias

This commit is contained in:
Jon Leighton 2012-07-13 11:44:35 +01:00
parent 1420d4e42f
commit 4b4a85515b
3 changed files with 12 additions and 2 deletions

View File

@ -5,7 +5,7 @@ gemspec
if ENV['AREL']
gem 'arel', path: ENV['AREL']
else
gem 'arel'
gem 'arel', github: 'rails/arel'
end
gem 'mocha', '>= 0.11.2', :require => false

View File

@ -552,7 +552,7 @@ module ActiveRecord
end
def build_arel
arel = table.from table
arel = Arel::SelectManager.new(table.engine, table)
build_joins(arel, joins_values) unless joins_values.empty?

View File

@ -1332,4 +1332,14 @@ class RelationTest < ActiveRecord::TestCase
assert_equal expected, relation.inspect
end
end
test 'using a custom table affects the wheres' do
table_alias = Post.arel_table.alias('omg_posts')
relation = ActiveRecord::Relation.new Post, table_alias
relation.where!(:foo => "bar")
node = relation.arel.constraints.first.grep(Arel::Attributes::Attribute).first
assert_equal table_alias, node.relation
end
end