Created
December 13, 2009 01:45
-
-
Save zapnap/255202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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