aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb26
-rw-r--r--activerecord/test/cases/relation/where_chain_test.rb19
3 files changed, 4 insertions, 46 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 9798f783c1..82266fe1d5 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,11 +1,10 @@
## Rails 4.0.0 (unreleased) ##
-* Allow `Relation#where` with no arguments to be chained with new query methods
- `not`, `like`, and `not_like`.
+* Allow `Relation#where` with no arguments to be chained with new `not` query method.
Example:
- Developer.where.not(name: 'Aaron').where.like(name: 'Takoyaki%')
+ Developer.where.not(name: 'Aaron')
*Akira Matsuda*
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 9484092430..f6d106f304 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -47,32 +47,6 @@ module ActiveRecord
@scope.where_values += where_value
@scope
end
-
- # Returns a new relation expressing WHERE + LIKE condition
- # according to the conditions provided as a hash in the arguments.
- #
- # Book.where.like(title: "Rails%")
- # # SELECT * FROM books WHERE title LIKE 'Rails%'
- def like(opts, *rest)
- where_value = @scope.send(:build_where, opts, rest).map do |rel|
- Arel::Nodes::Matches.new(rel.left, rel.right)
- end
- @scope.where_values += where_value
- @scope
- end
-
- # Returns a new relation expressing WHERE + NOT LIKE condition
- # according to the conditions provided as a hash in the arguments.
- #
- # Conference.where.not_like(name: "%Kaigi")
- # # SELECT * FROM conferences WHERE name NOT LIKE '%Kaigi'
- def not_like(opts, *rest)
- where_value = @scope.send(:build_where, opts, rest).map do |rel|
- Arel::Nodes::DoesNotMatch.new(rel.left, rel.right)
- end
- @scope.where_values += where_value
- @scope
- end
end
Relation::MULTI_VALUE_METHODS.each do |name|
diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb
index edb3ea48b9..8ce44636b4 100644
--- a/activerecord/test/cases/relation/where_chain_test.rb
+++ b/activerecord/test/cases/relation/where_chain_test.rb
@@ -62,29 +62,14 @@ module ActiveRecord
assert_equal([expected], relation.where_values)
end
- def test_like
- expected = Arel::Nodes::Matches.new(Post.arel_table[:title], 'a%')
- relation = Post.where.like(title: 'a%')
- assert_equal([expected], relation.where_values)
- end
-
- def test_not_like
- expected = Arel::Nodes::DoesNotMatch.new(Post.arel_table[:title], 'a%')
- relation = Post.where.not_like(title: 'a%')
- assert_equal([expected], relation.where_values)
- end
-
def test_chaining_multiple
- relation = Post.where.like(title: 'ruby on %').where.not(title: 'ruby on rails').where.not_like(title: '% ales')
+ relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails')
- expected = Arel::Nodes::Matches.new(Post.arel_table[:title], 'ruby on %')
+ expected = Arel::Nodes::NotIn.new(Post.arel_table[:author_id], [1, 2])
assert_equal(expected, relation.where_values[0])
expected = Arel::Nodes::NotEqual.new(Post.arel_table[:title], 'ruby on rails')
assert_equal(expected, relation.where_values[1])
-
- expected = Arel::Nodes::DoesNotMatch.new(Post.arel_table[:title], '% ales')
- assert_equal(expected, relation.where_values[2])
end
end
end