Skip to content

Instantly share code, notes, and snippets.

@zmack
Created August 13, 2010 11:47
Show Gist options
  • Save zmack/522738 to your computer and use it in GitHub Desktop.
Save zmack/522738 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
class User
include DataMapper::Resource
property :id, Serial
property :login, String
attr_accessor :foo
before :save, :bar
def bar
self.login = @foo || "horse"
end
end
DataMapper.setup :default, "sqlite3:data.sqlite"
DataMapper.auto_upgrade!
z = User.create
# login is "horse"
z.foo = "bat"
z.save
p z.reload.login
# i'd like login to be "bat", but it's "horse" :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment