How do I reference self in the following?
scope :children, where("parent_id = ?", self.id)
self doesn’t seem to work in this context
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Normally scopes are chained off the class, like this:
You’d need a lambda scope to get the same behavior:
I’m assuming you’re trying to get a specific instance’s children:
This would be an instance method, but: this looks like a basic self-referencing association, too, rather than something needing a scope.
If you’re making a tree there are gems for that, e.g., closure-tree, ancestry, and others.