gpt4 book ai didi

javascript - 如何在 Objection.js 中创建两个外键关系

转载 作者:行者123 更新时间:2023-12-02 03:18:54 27 4
gpt4 key购买 nike

有没有办法在 Objection.js 中创建两个外键关系。类似于以下内容:

  static get relationMappings() {
return {
childs: {
relation: Model.HasManyRelation,
modelClass: childModel,
join: {
from: 'parent.id',
to: 'child.parent_id'
},
join: { // Another foreign key
from: 'parent.record_id',
to: 'child.parent_record_id'
}
}
}
}

最佳答案

最后我在docs找到了解决方案

  static get relationMappings() {
return {
childs: {
relation: Model.HasManyRelation,
modelClass: childModel,
join: {
from: [
'parent.id',
'parent.record_id'
],
to: [
'child.parent_id',
'child.parent_record_id'
]
},
}
}
}

关于javascript - 如何在 Objection.js 中创建两个外键关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55396729/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com