Permalink
Browse files

unscoped does not work when chained with named_scope

  • Loading branch information...
1 parent 3a831cb commit 2ae4f016507a57a261ea3dc20f1314beac283d3f Neeraj Singh committed with fxn Aug 23, 2010
Showing with 5 additions and 0 deletions.
  1. +5 −0 activerecord/lib/active_record/base.rb
@@ -876,6 +876,11 @@ def arel_engine
# 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

0 comments on commit 2ae4f01

Please sign in to comment.