From 8d02afeaee8993bd0fde69687fdd9bf30921e805 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 7 Dec 2012 16:52:55 -0200 Subject: Rollback where.like and where.not_like The real win with these chain methods is where.not, that takes care of different scenarios in a graceful way, for instance when the given value is nil. where("author.id != ?", author_to_ignore.id) where.not("author.id", author_to_ignore.id) Both where.like and where.not_like compared to the SQL versions doesn't seem to give us that much: Post.where("title LIKE 'ruby on%'") Post.where.like(title: 'ruby on%'") Post.where("title NOT LIKE 'ruby on%'") Post.where.not_like(title: 'ruby on%'") Thus Rails is adding where.not, but not where.like/not_like and others. --- .../lib/active_record/relation/query_methods.rb | 26 ---------------------- 1 file changed, 26 deletions(-) (limited to 'activerecord/lib/active_record') 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| -- cgit v1.2.3