Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Improved named_scope to be used like as with_scope

#739

named_scope is really cool feature of the latest Ruby on Rails, but it can't be used with good old with_scope.

So I implemented "with" method to the Scope class so that we can use a scoped block like this:

User.active.with do
  User.count #=> equals to User.active.count
end

Reported by Genki Takiuchi · August 1st, 2008 @ 10:53 AM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Genki Takiuchi
  2. Paweł Kondzior
  3. Genki Takiuchi
  4. Ryan Bates
    Ryan Bates

    I just needed this functionality not too long ago, and the implementation looks nice and simple. However, it looks like tests are missing, could you add some?

    August 1st, 2008 @ 06:07 PM

  5. Ryan Bates
  6. Ryan Bates
    Ryan Bates

    I've been playing around with this a little bit and found out you can completely remove the "with" method on the Scope class and it will still behave properly. This is because when you call "with" it will be delegated to the proxy scope and already apply with_scope.

    I propose not using the "with" method at all and just sticking to with_scope. This required a couple minor changes but I've attached a patch which does this.

    User.active.with_scope do
      User.count #=> equals to User.active.count
    end
    

    August 1st, 2008 @ 08:42 PM

  7. Genki Takiuchi
  8. Pratik
    Pratik
    • State changed from new to wontfix

    This is not very with_scope like as with_scope was made a private method after people started abusing it in around_filter, which is against Rails way of doing things.

    This should still work, however it should be a protected method.

    Might be a good idea to discuss in the mailing list.

    Thanks.

    August 22nd, 2008 @ 04:13 AM