This project is archived and is in readonly mode.

#1463 ✓invalid


Reported by qoobaa | November 24th, 2008 @ 10:59 PM | in 2.x

The patch adds new scope functionality that I've found very useful in my project. It simply adds new instance method called in_scope? to each defined named_scope. I use it in several cases, i.e.

class User
  named_scope :destroyable, :conditions => "..." # simple association check
  before_destroy :in_destroyable?

user = User.destroyable.first

user.in_destroyable? # the same as User.destroyable.include?(user)
#=> true

Firstly I used :destroyable? method (without "in_") but it may collide with some boolean attributes like "active", etc. Implementation is very simple and it uses ordinary :include? method to check the inclusion. Probably it can be optimised to do the inclusion check in SQL, but for me it's really enough.

Comments and changes to this ticket

  • Pratik

    Pratik March 7th, 2009 @ 03:58 PM

    • Assigned user set to “Pratik”
    • Tag changed from activerecord, edge, enhancement, named_scope, tested to activerecord, edge, enhancement, named_scope, patch, tested
    • State changed from “new” to “invalid”

    I don't think this belongs to core. Also, you could just use exists? though.


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>

People watching this ticket