-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.rb
50 lines (37 loc) · 861 Bytes
/
model.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
require 'rubygems'
require 'sinatra'
require 'data_mapper'
require 'rack-flash'
require 'bcrypt'
DataMapper::setup(:default, "sqlite://#{Dir.pwd}/db.sqlite")
class User
include DataMapper::Resource
include BCrypt
property :id, Serial, :key => true
property :username, String, :length => 3..50
property :email, String
property :password, BCryptHash
has n, :cart
end
class Product
include DataMapper::Resource
property :id, Serial, :key => true
property :name, String
property :price, Float
has n, :cartItem
end
class Cart
include DataMapper::Resource
property :id, Serial, :key => true
belongs_to :user
has n, :cartItem
end
class CartItem
include DataMapper::Resource
property :id, Serial, :key => true
property :quantity, Integer
belongs_to :cart
belongs_to :product
end
DataMapper.finalize
DataMapper.auto_upgrade!