Created
February 28, 2010 15:46
-
-
Save schmurfy/317644 to your computer and use it in GitHub Desktop.
DataMapper Quick Reference
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
# some more: http://cheat.errtheblog.com/s/datamapper/ | |
# results of first steps with datamapper and lack of documentation | |
# use a bigint unsigned column as primary key | |
property :id, Serial, :min => 0, :max => 2**32 | |
# automagically create database from your model definitions (destructive !) | |
DataMapper.auto_migrates! | |
<Model>.auto_migrate! | |
# try to migrate schema doing required changes (data are safe but this method seems rather limited in what can be done) | |
DataMapper.auto_upgrade! | |
<Model>.auto_upgrade! | |
# define hooks | |
before(:create) { ... } # unlike activerecord the block is called in the object context, self point to the object not the class | |
before(:create, :assign_something) # call the method on the object | |
after(:create) { ... } | |
valid phases are: | |
:create | |
:update | |
:destroy | |
# set the default database for a given model | |
class User | |
def self.default_repository_name | |
:other | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment