I cam across #1677 Association proxies using class methods with named scopes - Ruby on Rails - rails yesterday. In a nutshell it boils down to
Post.with_scope(:find => ...) { Post.some_scope.find :all }
returns posts scoped by both the call to with_scope and the call to some_scope, but
Post.with_scope(:find => ...) { Post.some_scope}.find :all
returns posts only scoped by some_scope
Just like that it doesn't look too bad: the find happens outside with_scope's block and so it doesn't get scoped. Quel surprise.
However it means that for example if we have
class Post named_scope :base def self.get_me_a_scope base end end
then
some_user.posts.get_me_a_scope.find :all
will return posts from all users, which seems a bad thing. gist:42383 · GitHub seems to fix that particular but causes a failing test on default_scope (which I haven't really been following so I'm not 100% aware of what should and should not be)
Fred