This project is archived and is in readonly mode.

#1463 ✓invalid
qoobaa

in_scope?

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?
end

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.

    Thanks.

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages