This project is archived and is in readonly mode.

#223 ✓wontfix
Henrik Nyh

named_scope that composes other named_scopes

Reported by Henrik Nyh | May 19th, 2008 @ 05:32 PM

It would be very useful if you could do e.g.

named_scope :published, ...
named_scope :japanese, ...
named_scope :popular, :conditions => ..., :compose => :published
named_scope :big_in_japan, :compose => [:japanese, :popular]

so that


will incorporate the "published", "japanese" and "popular" conditions etc in a DRY way. I love named_scope, but I sometimes end up with chains that are too long for comfort.

Comments and changes to this ticket

  • Ryan Bates

    Ryan Bates May 20th, 2008 @ 06:15 PM

    That's a pretty cool idea. It's similar to ticket #57.

    I'm wondering if the :include option might be a good spot for this. Currently it's just used to manage associations, but what if you could include named scopes? This has the side benefit that you can use it in any "find" call as well as the named scope. It also would allow you to include named scopes through associations. For example:

    class Category
      has_many :products
      named_scope :visible, :conditions => { :hidden => false }
    class Product
      belongs_to :category
      named_scope :released, :conditions => "products.released_at IS NOT NULL"
      named_scope :visible, :include => [:released, {:category => :visible}]

    Okay, probably just a crazy idea that would be ridiculously complicated to implement. But a fun thought none-the-less.

  • josh

    josh July 17th, 2008 @ 01:50 AM

    • Assigned user set to “Pratik”
    • Tag set to activerecord, enhancement, named_scope
  • Pratik

    Pratik July 18th, 2008 @ 03:26 AM

    • State changed from “new” to “wontfix”

    Closing until we have a patch. Also looks like a duplicate of #57 which has a patch.


Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>