Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# unable to save / update a record (without validations) when dm after save callback is used
# what's strange(r) is that the call to update! returns true here...
require 'dm-core'
class Project
include DataMapper::Resource
property :id, Serial
property :name, String
property :status, String, :default => 'default'
# generate updated project docs
after :save do
update_status
end
def update_status
ret = update!(:status => 'updated')
puts "set status of #{id} to '#{status}' in after save callback (update! returns #{ret})"
end
end
DataMapper.setup(:default, "sqlite3:memory:")
DataMapper.auto_migrate!
project = Project.new(:name => 'test')
project.save
project = Project.get(project.id)
puts "but when we later fetch record #{project.id}, status is '#{project.status.nil? ? 'nil' : project.status}'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment