Permalink
Browse files

support relations created with a table alias

  • Loading branch information...
1 parent 1420d4e commit 4b4a85515bbae4ec88547727a5f7f17bc5cefdce @jonleighton jonleighton committed Jul 13, 2012
Showing with 12 additions and 2 deletions.
  1. +1 −1 Gemfile
  2. +1 −1 activerecord/lib/active_record/relation/query_methods.rb
  3. +10 −0 activerecord/test/cases/relations_test.rb
View
@@ -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
@@ -552,7 +552,7 @@ def arel
end
def build_arel
- arel = table.from table
+ arel = Arel::SelectManager.new(table.engine, table)
build_joins(arel, joins_values) unless joins_values.empty?
@@ -1332,4 +1332,14 @@ def test_presence
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

1 comment on commit 4b4a855

I wonder if Rails 4.0 support Ruby 1.8.7 hash syntax?

Please sign in to comment.