I use datamapper for the database. I have a table.
class ZedTable
include DataMapper::Resource
property :id, Serial
property :label, String
property :now, Boolean, :default => false
before :save do
ZedTable.all.update(:now => false)
self.now = true
end
end
That is, I want only one value was true. But when I save the data I get an error.
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
Why? And how do I solve this problem?
Thanks.
You get are getting
stack too deepbecause when you callupdate, it first callsbefore :savehook again. The method you need isupdate!, it bypasses the hooks.