unscoped does not work when chained with named_scope

This commit is contained in:
Neeraj Singh
2010-08-23 05:45:11 -04:00
committed by Xavier Noria
parent 3a831cb7d6
commit 2ae4f01650

View File

@@ -876,6 +876,11 @@ module ActiveRecord #:nodoc:
# limit(10) # Fires "SELECT * FROM posts LIMIT 10"
# }
#
# It is recommended to use block form of unscoped because chaining unscoped with <tt>named_scope</tt>
# does not work. Assuming that <tt>published</tt> is a <tt>named_scope</tt> following two statements are same.
#
# Post.unscoped.published
# Post.published
def unscoped
block_given? ? relation.scoping { yield } : relation
end