Ras*_*mon 2 javascript node.js objection.js
有没有办法在 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'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后我在文档中找到了解决方案
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'
]
},
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
351 次 |
| 最近记录: |