Browse Source

fix: convert foreign key based on column type

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/614/head
Pranav C 3 years ago
parent
commit
6fc32b31d8
  1. 2
      packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue
  2. 18
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue

2
packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue

@ -83,7 +83,7 @@ import FormulaCell from '@/components/project/spreadsheet/components/virtualCell
import hasManyCell from '@/components/project/spreadsheet/components/virtualCell/hasManyCell'
import LookupCell from '@/components/project/spreadsheet/components/virtualCell/lookupCell'
import manyToManyCell from '@/components/project/spreadsheet/components/virtualCell/manyToManyCell'
import belongsToCell from '@/components/project/spreadsheet/components/virtualCell/belogsToCell'
import belongsToCell from '@/components/project/spreadsheet/components/virtualCell/belongsToCell'
// todo: optimize parent/child meta extraction

18
packages/nc-gui/components/project/spreadsheet/components/virtualCell/belogsToCell.vue → packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue

@ -164,7 +164,9 @@ export default {
return this.parentMeta && (this.parentMeta.columns.find(c => c.pk) || {})._cn
},
parentQueryParams() {
if (!this.parentMeta) { return {} }
if (!this.parentMeta) {
return {}
}
// todo: use reduce
return {
hm: (this.parentMeta && this.parentMeta.v && this.parentMeta.v.filter(v => v.hm).map(({ hm }) => hm.tn).join()) || '',
@ -174,7 +176,9 @@ export default {
},
parentAvailableColumns() {
const hideCols = ['created_at', 'updated_at']
if (!this.parentMeta) { return [] }
if (!this.parentMeta) {
return []
}
const columns = []
if (this.parentMeta.columns) {
@ -299,9 +303,15 @@ export default {
this.newRecordModal = true
},
async addChildToParent(parent) {
const pid = this.parentMeta.columns.filter(c => c.pk).map(c => parent[c._cn]).join('___')
const pkColumns = this.parentMeta.columns.filter(c => c.pk)
const pid = pkColumns.map(c => parent[c._cn]).join('___')
const id = this.meta.columns.filter(c => c.pk).map(c => this.row[c._cn]).join('___')
const _cn = this.meta.columns.find(c => c.cn === this.bt.cn)._cn
let isNum = false
if (pkColumns.length === 1) {
isNum = ['float', 'integer'].includes(this.sqlUi.getAbstractType(pkColumns[0]))
}
if (this.isNew) {
this.localState = parent
@ -311,7 +321,7 @@ export default {
}
await this.api.update(id, {
[_cn]: pid
[_cn]: isNum ? +pid : pid
}, {
[_cn]: this.value && this.value[this.parentPrimaryKey]
})
Loading…
Cancel
Save