Skip to content

Instantly share code, notes, and snippets.

@jackowayed
Created January 26, 2009 23:07
Show Gist options
  • Save jackowayed/53024 to your computer and use it in GitHub Desktop.
Save jackowayed/53024 to your computer and use it in GitHub Desktop.
My illustration of why AR migrations suck and DM properties don't
# Migrations are ugly and make you write a lot of code you don't need.
#in AR
# from http://wiki.rubyonrails.org/rails/pages/UnderstandingMigrations
class AddANewTable < ActiveRecord::Migration #these 3 lines
def self.up #are just a very verbose way to say
create_table :users do |table| # to make a table
table.column :name, :string
# This column will contain an MD5 hash.
table.column :login, :string, :null => false
table.column :password, :string, :limit => 32, :null => false
table.column :email, :string
end
end
def self.down
drop_table :users
end
end
# in DM
#in your model
include DataMapper::Resource #just 1 line
#let's treat what essentially act like instance variables like instance variables!
property :id, Serial #in DM, you could even have a String id! AR strongly discourages it. and there are composite keys
property :name, String
property :login, String, :nullable => false
property :password, String, :length => 32, :nullable => false #you call the maximum length 'length'!
property :email, String
# basically, it's prettier, less code, and more semantic, and the model's properties are in the model file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment