I'm trying to override the all()
and first()
methods in a DataMapper model I have, but there are some issues. My methods are being called, but (as became immediately obvious) they call themselves recursively and cause a SystemStackError.
class Model
include DataMapper::Resource
include OtherModule
def self.all(options = {})
do_something()
self.all(options.merge!(:deleted => false))
end
def self.first(options = {})
self.first(options.merge!(:deleted => false))
end
property :id, Serial
property :name, Text
...
All these methods should do is call the all
or first
method with :deleted => false
unless otherwise specified.
I tried
def self.all(options = {})
super.self.all(options.merge!(:deleted => false))
end
and
def self.all(options = {})
do_something()
super.all(options.merge!(:deleted => false))
end
to no avail. Is there a way around this infinite recursion problem?