0

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?

AlexQueue
  • 6,353
  • 5
  • 35
  • 44

1 Answers1

1

You are misusing super

def self.all(options={})
    do_something()
    super(options.merge!(:deleted => false))
 end
Sandy Vanderbleek
  • 1,082
  • 1
  • 12
  • 13