where.not adds references for includes.

Closes #14406.
This commit is contained in:
Yves Senn 2014-03-17 14:20:23 +01:00
parent 378c8d2c99
commit 8ba60912ca
4 changed files with 26 additions and 0 deletions

@ -1,3 +1,9 @@
* `where.not` adds `references` for `includes` like normal `where` calls do.
Fixes #14406.
*Yves Senn*
* Extend fixture `$LABEL` replacement to allow string interpolation.
Example:

@ -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

@ -1366,6 +1366,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