From 2ae4f016507a57a261ea3dc20f1314beac283d3f Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 23 Aug 2010 05:45:11 -0400 Subject: [PATCH] unscoped does not work when chained with named_scope --- activerecord/lib/active_record/base.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ed15d7d4ec..d7ef19dbee 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -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 named_scope + # does not work. Assuming that published is a named_scope following two statements are same. + # + # Post.unscoped.published + # Post.published def unscoped block_given? ? relation.scoping { yield } : relation end