17. models/user.rb
class User
include DataMapper::Resource
Merb::Authentication.user_class = self
property :id, Serial
property :login, String
end
18. controllers/articles.rb
class Article < Application
provides :xml, :yaml, :js
before :ensure_authenticated
def show
@article = Article.get(params[:id])
raise NotFound unless @article
display @article
end
end
19. DataMapper
# queries
Article.all
Article.first :order => [:created_at.desc]
Article.get(params[:id])
#validations
validates_present :title
validates_is_number :rating
#associations
has n, :comments
belongs_to :blog
has 1, :author