DataMapper 0.9 is Released
DataMapper 0.9 is ready for the world. It brings with it a massive overhaul of the internals of DataMapper, a shift in terminology, a dramatic bump in speed, improved code-base organization, and support for more than just database data-stores.
To install it:
sudo gem install addressable english rspec sudo gem install data_objects do_mysql do_postgres do_sqlite3 sudo gem install dm-core dm-more
This is NOT a backwards compatible release. Code written for DataMapper 0.3 will not function with DataMapper 0.9.* due to syntactical changes and library improvements.
REPEAT: This is NOT a backwards compatible release.
| DataMapper 0.3 | DataMapper 0.9 | |
|---|---|---|
| Creating a class |
class Post < DataMapper::Base end |
class Post include DataMapper::Resource end |
| Keys |
# Key was not mandatory # Automatically added +id+ if missing # # Natural Key property :name, :string, :key => true # # Composite Key property :id, :integer, :key => true property :slug, :string, :key => true |
# keys are now mandatory property :id, Integer, :serial => true # # Natural Key property :slug, String, :key => true # # Composite Key property :id, Integer, :key => true property :slug, String, :key => true |
| Properties |
property :title, :string property :body, :text property :posted_on, :datetime property :active, :boolean |
property :title, String property :body, Text property :posted_on, DateTime property :active, Boolean |
| Associations |
has_many :comments belongs_to :blog has_and_belongs_to_many :categories has_one :author |
has n, :comments belongs_to :blog has n, :categories => Resource has 1, :author |
| Finders |
Post.first :order => ‘created_at DESC’ |
Post.first :order => [:created_at.desc] |
| Validations |
validates_presence_of :title |
validates_present :title |
| Callbacks |
before_save :categorize before_create do |post| # do stuff with post end # return false to abort |
before :save, :categorize before :create do # do stuff with self end # throw :halt to abort |