非id字段上的环回关系 [英] Loopback relationship on non id field

查看:60
本文介绍了非id字段上的环回关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想指定2个mssql表之间的关系. 付款类别和付款. Paymentcategory.id加入payout.category列.

I want to specify the relationship betweet 2 mssql tables. Paymentcategory and Payout. paymentcategory.id joins on the payout.category column.

在payout.json模型中 我指定为foreignKey:id,

in payout.json model I specified as foreignKey: id,

"relations": {
    "paymentcategories": {
      "type": "hasOne",
      "model": "Paymentcategory",
      "foreignKey": "id"
 }

但是默认情况下,环回查找id字段为primaryKey

but loopback looks by default for the id field as primaryKey

是否可以在类别字段上指定联接. 最好在common/models/payout.json文件中?

Is there a way to specify the join on the category field. Preferably in the common/models/payout.json file?

"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中.

You can defined your foreign key to be whatever you want (in /common/models/your-model-name.json.

请参见 https://github.com/strongloop/loopback-example-关系基础以获取更多信息.

See my example at https://github.com/strongloop/loopback-example-relations-basic for more info.

这篇关于非id字段上的环回关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆