aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJuanjo Bazán <jjbazan@gmail.com>2012-09-25 00:59:07 +0200
committerJuanjo Bazán <jjbazan@gmail.com>2012-10-28 22:18:45 +0100
commit300d080ada31ac297264e6abba6ca16cd2db5925 (patch)
tree253d70f1bfc68985181c1f683444c5918a6550f1 /activerecord
parent35ca953a27124bd6dcd7aef8a62ffa27ccab83f1 (diff)
downloadrails-300d080ada31ac297264e6abba6ca16cd2db5925.tar.gz
rails-300d080ada31ac297264e6abba6ca16cd2db5925.tar.bz2
rails-300d080ada31ac297264e6abba6ca16cd2db5925.zip
ActiveRecord::Relation#none! method.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb5
-rw-r--r--activerecord/test/cases/relation_test.rb6
3 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 684a8736c9..f7aed090a4 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Added `#none!` method for mutating `ActiveRecord::Relation` objects to a NullRelation.
+ It acts like `#none` but modifies relation in place.
+
+ *Juanjo Bazán*
+
* Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
*Henrik Nyh*
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 14bcb337e9..4fdc296c7e 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -496,6 +496,11 @@ module ActiveRecord
extending(NullRelation)
end
+ # Like #none, but modifies relation in place.
+ def none!
+ extending!(NullRelation)
+ end
+
# Sets readonly attributes for the returned relation. If value is
# true (default), attempting to update a record will result in an error.
#
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb
index 6399111be6..98e278df82 100644
--- a/activerecord/test/cases/relation_test.rb
+++ b/activerecord/test/cases/relation_test.rb
@@ -256,5 +256,11 @@ module ActiveRecord
test 'merge with a proc' do
assert_equal [:foo], relation.merge(-> { where(:foo) }).where_values
end
+
+ test 'none!' do
+ assert relation.none!.equal?(relation)
+ assert_equal [NullRelation], relation.extending_values
+ assert relation.is_a?(NullRelation)
+ end
end
end