set up orders model and relationships

This commit is contained in:
2017-01-26 17:50:56 -07:00
parent a41c7428b9
commit ea5de580a8
8 changed files with 116 additions and 4 deletions

View File

@@ -39,7 +39,13 @@
} }
}, },
"validations": [], "validations": [],
"relations": {}, "relations": {
"orders": {
"type": "hasMany",
"model": "order",
"foreignKey": "customerId"
}
},
"acls": [], "acls": [],
"methods": {} "methods": {}
} }

View File

@@ -0,0 +1,5 @@
'use strict';
module.exports = function(Orderproducts) {
};

View File

@@ -0,0 +1,41 @@
{
"name": "orderProducts",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "string",
"required": true
},
"quantity": {
"type": "number",
"required": true
},
"price": {
"type": "number",
"required": true
},
"totalPrice": {
"type": "number",
"required": true
}
},
"validations": [],
"relations": {
"order": {
"type": "belongsTo",
"model": "order",
"foreignKey": ""
},
"product": {
"type": "belongsTo",
"model": "product",
"foreignKey": ""
}
},
"acls": [],
"methods": {}
}

5
common/models/order.js Normal file
View File

@@ -0,0 +1,5 @@
'use strict';
module.exports = function(Order) {
};

38
common/models/order.json Normal file
View File

@@ -0,0 +1,38 @@
{
"name": "order",
"plural": "orders",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "string",
"required": true
},
"total": {
"type": "number",
"required": true
},
"datetime": {
"type": "date"
}
},
"validations": [],
"relations": {
"customer": {
"type": "belongsTo",
"model": "customer",
"foreignKey": ""
},
"products": {
"type": "hasMany",
"model": "product",
"foreignKey": "",
"through": "orderProducts"
}
},
"acls": [],
"methods": {}
}

View File

@@ -28,7 +28,14 @@
} }
}, },
"validations": [], "validations": [],
"relations": {}, "relations": {
"orders": {
"type": "hasMany",
"model": "order",
"foreignKey": "",
"through": "orderProducts"
}
},
"acls": [], "acls": [],
"methods": {} "methods": {}
} }

View File

@@ -6,7 +6,8 @@
"RoleMapping": 1, "RoleMapping": 1,
"Role": 1, "Role": 1,
"customer": 1, "customer": 1,
"product": 1 "product": 1,
"order": 1
}, },
"models": { "models": {
"User": {}, "User": {},
@@ -15,6 +16,7 @@
"RoleMapping": {}, "RoleMapping": {},
"Role": {}, "Role": {},
"customer": {}, "customer": {},
"product": {} "product": {},
"order": {}
} }
} }

View File

@@ -36,8 +36,16 @@
"dataSource": "db", "dataSource": "db",
"public": true "public": true
}, },
"order": {
"dataSource": "db",
"public": true
},
"product": { "product": {
"dataSource": "db", "dataSource": "db",
"public": true "public": true
},
"orderProducts": {
"dataSource": "db",
"public": false
} }
} }