Permalink
Browse files

`where.not` adds `references` for `includes`.

Closes #14406.

Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information...
senny committed Mar 17, 2014
1 parent 2be3a2c commit 4c0d6680ee011b822e6beaa1ee84f835e89550a1
@@ -1,3 +1,9 @@
+* `where.not` adds `references` for `includes` like normal `where` calls do.
+
+ Fixes #14406.
+
+ *Yves Senn*
+
* `includes` is able to detect the right preloading strategy when string
joins are involved.
@@ -49,6 +49,8 @@ def not(opts, *rest)
Arel::Nodes::Not.new(rel)
end
end
+
+ @scope.references!(PredicateBuilder.references(opts)) if Hash === opts
@scope.where_values += where_value
@scope
end
@@ -1203,4 +1203,14 @@ def test_deep_including_through_habtm
assert_equal 5, author.posts.size
}
end
+
+ test "including associations with where.not adds implicit references" do
+ author = assert_queries(2) {
+ Author.includes(:posts).where.not(posts: { title: 'Welcome to the weblog'} ).last
+ }
+
+ assert_no_queries {
+ assert_equal 2, author.posts.size
+ }
+ end
end
@@ -1342,6 +1342,14 @@ def test_automatically_added_where_references
assert_equal ['comments'], scope.references_values
end
+ def test_automatically_added_where_not_references
+ scope = Post.where.not(comments: { body: "Bla" })
+ assert_equal ['comments'], scope.references_values
+
+ scope = Post.where.not('comments.body' => 'Bla')
+ assert_equal ['comments'], scope.references_values
+ end
+
def test_automatically_added_having_references
scope = Post.having(:comments => { :body => "Bla" })
assert_equal ['comments'], scope.references_values

0 comments on commit 4c0d668

Please sign in to comment.