-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.rb
61 lines (45 loc) · 1.39 KB
/
models.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'data_mapper'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, "sqlite:///#{File.dirname(__FILE__)}/blogging.db")
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :required => true
property :body, Text, :required => true
property :created_at, DateTime
has n, :comments
has n, :categorizations
has n, :categories, :through => :categorizations
end
class Comment
include DataMapper::Resource
property :id, Serial
property :posted_by, String, :required => true
property :url, String, :format => :url
property :body, Text, :required => true
property :created_at, DateTime
belongs_to :post
end
class Category
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :categorizations
has n, :posts, :through => :categorizations
end
class Categorization
include DataMapper::Resource
property :id, Serial
property :created_at, DateTime
belongs_to :category
belongs_to :post
end
class User
include DataMapper::Resource
property :id, Serial
property :user_name, String, :required => true, :unique => true
property :password, String, :length => 40, :required => true
property :email, String, :format => :email_address
property :is_admin, Boolean, :default => false
end
DataMapper.finalize