Skip to content

Instantly share code, notes, and snippets.

@zapnap
Created December 13, 2009 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapnap/255202 to your computer and use it in GitHub Desktop.
Save zapnap/255202 to your computer and use it in GitHub Desktop.
# 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