aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2017-07-17 13:41:37 -0500
committerGitHub <noreply@github.com>2017-07-17 13:41:37 -0500
commitcdf4046430a9d837509f0ca4a1dde7d8c93a34f7 (patch)
treed61ff407fa95c3bb26fafadb53f98c236f0c76c1 /activerecord
parent1b62f066d529452166d4b1a2c301e663e9ff397c (diff)
parent26ba655f36c20315390497a0963c23014cadeb91 (diff)
downloadrails-cdf4046430a9d837509f0ca4a1dde7d8c93a34f7.tar.gz
rails-cdf4046430a9d837509f0ca4a1dde7d8c93a34f7.tar.bz2
rails-cdf4046430a9d837509f0ca4a1dde7d8c93a34f7.zip
Merge pull request #29796 from kamipo/fix_where_with_custom_table
Fix `where` with a custom table
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb8
2 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 8c2d546aff..c26c176c7b 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -1048,7 +1048,7 @@ module ActiveRecord
if select_values.any?
arel.project(*arel_columns(select_values.uniq))
else
- arel.project(@klass.arel_table[Arel.star])
+ arel.project(table[Arel.star])
end
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 6c35940c2e..ca15c95432 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1915,11 +1915,11 @@ class RelationTest < ActiveRecord::TestCase
table_metadata = ActiveRecord::TableMetadata.new(Post, table_alias)
predicate_builder = ActiveRecord::PredicateBuilder.new(table_metadata)
- relation = ActiveRecord::Relation.new(Post, table_alias, predicate_builder)
- relation.where!(foo: "bar")
+ relation = ActiveRecord::Relation.create(Post, table_alias, predicate_builder)
- node = relation.arel.constraints.first.grep(Arel::Attributes::Attribute).first
- assert_equal table_alias, node.relation
+ post = posts(:welcome)
+
+ assert_equal post, relation.where!(title: post.title).take
end
test "#load" do