-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.rb
52 lines (39 loc) · 1008 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
51
52
## requires
require 'sinatra'
require 'rubygems'
require 'sinatra/base'
require 'json'
require 'time'
require 'pp'
### datamapper requires
require 'data_mapper'
require 'dm-types'
require 'dm-timestamps'
require 'dm-validations'
class Product
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :brand, String
property :description, String
property :quantity, Integer
property :price, Float
belongs_to :subcategory, :key => true
end
class Category
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :description, String
has n, :subcategories
end
class Subcategory
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :description, String
belongs_to :category, :key => true
end
DataMapper.setup(:default, "sqlite3:test.db")
## create schema if necessary
DataMapper.auto_upgrade!