diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-07-13 11:44:35 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-07-13 11:44:45 +0100 |
commit | 4b4a85515bbae4ec88547727a5f7f17bc5cefdce (patch) | |
tree | 9c5b17843900dfb10f2be9f496e5b75c10631944 /activerecord | |
parent | 1420d4e42f75f3bb1a17ae81b463799ab9cb0596 (diff) | |
download | rails-4b4a85515bbae4ec88547727a5f7f17bc5cefdce.tar.gz rails-4b4a85515bbae4ec88547727a5f7f17bc5cefdce.tar.bz2 rails-4b4a85515bbae4ec88547727a5f7f17bc5cefdce.zip |
support relations created with a table alias
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index e401ed37b0..c567cc7cc4 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -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? diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 8713b8d5e4..c8da7ddd99 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -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 |