-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.html
70 lines (59 loc) · 1.6 KB
/
test.html
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
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="ldbx.js"></script>
<script>
var GenderModel = new Model({table: 'genders'})
var genders = [
{id: '1', code: 'M', name: 'male'},
{id: '2', code: 'F', name: 'femlae'},
]
genders.map(gender => {
if (!GenderModel.get().length) GenderModel.save(gender)
})
var genderList = GenderModel.get()
var PetModel = new Model('pets')
var pets = [
{id: '1', code: 'DG', name: 'DOG'},
{id: '2', code: 'BD', name: 'BIRD'},
{id: '3', code: 'BD', name: 'LOCNESS'},
]
pets.map(pet => {
if (!PetModel.get().length) PetModel.save(pet)
})
var petList = PetModel.get()
var UsersModel = new Model('users')
.belongsTo(GenderModel.tableName, 'gender_id', 'gender')
.belongsTo(PetModel.tableName, 'pet_id', 'pet')
.hasMany(PetModel.tableName, 'pet_code', 'pets', 'code')
UsersModel.fixStructure(['id', 'name', 'born_date', 'iq', 'is_alive', 'gender_id', 'pet_id', 'pet_code'])
var list = UsersModel.get()
list.map(user => {
if (user.iq === 120) {
user.gender_id = '1'
user.pet_id = '1'
user.pet_code = 'BD'
}
else {
user.gender_id = '2'
user.pet_id = '2'
user.pet_code = 'DG'
}
let Usm = new Model('users').where('id', user.id).update(user)
})
function init () {
console.log(UsersModel.belongsToRelation)
console.table(list)
console.table(genderList)
console.table(petList)
}
init()
</script>
</body>
</html>