Foo has_many Bar. I want to do something like:
foo_instance.bars.find_with_custom_stuff(baz)
How do I define find_with_custom_stuff so that it’s available on the bars relation? (and not just a Bar class method?)
update
I want to do something more complicated than a scope. something like:
def find_with_custom_stuff(thing)
if relation.find_by_pineapple(thing)
relation.find_by_pineapple(thing).monkey
else
:banana
end
end
Scopes,
scopein rails 3 andnamed_scopein rails 2.scopeshould return a scope, so given your update you probably don’t want to usescopehere. You can write a class method though, and usescopedto access the current scope, like: