【发布时间】:2015-11-04 22:44:04
【问题描述】:
我对loopback.io的belongsTo关系函数有点困惑
那么我们来看下面的例子:
我有一个名为 Project 的模型,它与 Customer 对象有关系。所以项目属于客户。
这是我的项目模型
{
"name": "Project",
"plural": "Projects",
"base": "PersistedModel",
"strict": false,
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"title": {
"type": "string",
"required": true
},
"description": {
"type": "string"
},
"dateCreated": {
"type": "date"
}
},
"validations": [],
"relations": {
"customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "customerId"
}
},
"acls": [],
"methods": {}
}
所以当我运行应用程序并转到 http://0.0.0.0:3000/explorer 时,我可以看到 API。但是当我去项目时,我只看到
GET /Projects/{id}/customer Fetches belongsTo relation customer.
我也期待其他功能,例如
POST /Projects/{id}/customer
DELETE /Projects/{id}/customer
为什么它们在这里不可用?或者如何通过 REST API 为项目设置客户?
【问题讨论】:
标签: loopbackjs strongloop