Created
August 13, 2010 11:47
-
-
Save zmack/522738 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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