loopback 3 通过 REST 管理 embedsMany api
loopback 3 manage embedsMany over REST api
我有一个环回模型pack
{
"name": "pack",
"plural": "packs",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"description1": {
"type": "string"
},
"description2": {
"type": "string"
}
},
"validations": [],
"relations": {
"products": {
"type": "embedsMany",
"model": "packProduct",
"property": "products",
"options": {
"validate": true,
"forceId": false
}
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$unauthenticated",
"permission": "DENY"
}
],
"methods": {},
"strict": true
}
现在 packProduct
模型
{
"name": "packProduct",
"plural": "packProducts",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"productId": {
"type": "string",
"required": true
},
"price": {
"type": "number",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {},
"strict": true
}
当我发送一个 POST 请求来创建一个只有一个名字的包时它有效,但是如果我发送
{
姓名:"test",
产品: []
}
我有The pack instance is not valid. Details: products is not defined in the model (value: undefined).
需要加入model-config.json
"packProduct": {
"dataSource": "transient",
"public": false
}
并且在datasources.json
"transient": {
"name": "transient",
"connector": "transient"
}
我有一个环回模型pack
{
"name": "pack",
"plural": "packs",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"description1": {
"type": "string"
},
"description2": {
"type": "string"
}
},
"validations": [],
"relations": {
"products": {
"type": "embedsMany",
"model": "packProduct",
"property": "products",
"options": {
"validate": true,
"forceId": false
}
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$unauthenticated",
"permission": "DENY"
}
],
"methods": {},
"strict": true
}
现在 packProduct
模型
{
"name": "packProduct",
"plural": "packProducts",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"productId": {
"type": "string",
"required": true
},
"price": {
"type": "number",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {},
"strict": true
}
当我发送一个 POST 请求来创建一个只有一个名字的包时它有效,但是如果我发送
{ 姓名:"test", 产品: [] }
我有The pack instance is not valid. Details: products is not defined in the model (value: undefined).
需要加入model-config.json
"packProduct": {
"dataSource": "transient",
"public": false
}
并且在datasources.json
"transient": {
"name": "transient",
"connector": "transient"
}