我想指定 2 mssql 表之间的关系。
付款类别和付款。
paymentcategory.id 加入 payout.category 列。
在 payout.json 模型中
我指定为外键:id,
"relations": {
"paymentcategories": {
"type": "hasOne",
"model": "Paymentcategory",
"foreignKey": "id"
}
但环回默认情况下将 id 字段视为主键
有没有办法在类别字段上指定连接。
最好在 common/models/payout.json 文件中?
"relations": {
"paymentcategories": {
"type": "hasOne",
"model": "Paymentcategory",
"foreignKey": "id",
"primaryKey": "category" ??????????????????
}
现在我收到这个错误:
"error": {
"name": "Error",
"status": 400,
"message": "Key mismatch: Paymentpayout.id: undefined, Paymentcategory.id: 1",
"statusCode": 400,
最佳答案
您可以将外键定义为您想要的任何内容(在 /common/models/your-model-name.json
中。
请参阅我的示例 https://github.com/strongloop/loopback-example-relations-basic了解更多信息。
关于loopbackjs - 非 id 字段上的环回关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26802071/