Browse Source

wip: cater fk not pk case

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>
pull/1333/head
Wing-Kam Wong 3 years ago
parent
commit
5cf3a236fe
  1. 28
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue
  2. 3
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

28
packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue

@ -2,7 +2,7 @@
<div class="d-flex d-100 chips-wrapper" :class="{active}">
<template v-if="!isForm">
<div class="chips d-flex align-center img-container flex-grow-1 hm-items">
<template v-if="value||localState">
<template v-if="value|| localState">
<item-chip
v-for="(ch,i) in (value|| localState)"
:key="i"
@ -54,7 +54,7 @@
:parent-meta="meta"
:query-params="{
...childQueryParams,
where: isNew ? null :`~not(${childForeignKey},eq,${parentId})~or(${childForeignKey},is,null)`,
where: isNew ? null :`~not(${childForeignKey},eq,${childForeignKeyVal != '' ? childForeignKeyVal : parentId})~or(${childForeignKey},is,null)`,
}"
:is-public="isPublic"
:password="password"
@ -80,7 +80,7 @@
:column="column"
:query-params="{
...childQueryParams,
where: `(${childForeignKey},eq,${parentId})`
where: `(${childForeignKey},eq,${childForeignKeyVal != '' ? childForeignKeyVal : parentId})`
}"
:is-public="isPublic"
:row-id="parentId"
@ -252,6 +252,9 @@ export default {
},
parentId() {
return this.meta && this.meta.columns ? this.meta.columns.filter(c => c.pk).map(c => this.row[c._cn]).join('___') : ''
},
childForeignKeyVal() {
return this.meta && this.meta.columns ? this.meta.columns.filter(c => c._cn === this.childForeignKey).map(c => this.row[c._cn]) : ''
}
},
watch: {
@ -347,7 +350,10 @@ export default {
this.newRecordModal = true
},
async addChildToParent(child) {
console.log("invoking addChildToParent ...")
console.log(child)
if (this.isNew && this.localState.every(it => it[this.childForeignKey] !== child[this.childPrimaryKey])) {
console.log(child)
this.localState.push(child)
this.$emit('update:localState', [...this.localState])
this.$emit('saveRow')
@ -359,15 +365,26 @@ export default {
const _cn = this.childForeignKey
this.newRecordModal = false
// wingkwong
console.log(_cn) // CustomerEmail
console.log(parseIfInteger(this.parentId)) // 1
console.log(child[this.childForeignKey]) // user1@test.com
console.log(this.hm)
// console.log(child[`${this.hm._rtn}Read`][this.hm && this.parentMeta && this.parentMeta.columns.find(v => v.pv)._cn])
// console.log((this.hm && child[`${this.hm._rtn}Read`] && child[`${this.hm._rtn}Read`][this.hm && _cn]) || parseIfInteger(this.parentId))
console.log(child[this.childPrimaryCol])
await this.childApi.update(id, {
[_cn]: parseIfInteger(this.parentId)
[_cn]: child[this.childForeignKey]
// [_cn]:
// (this.hm && child[`${this.hm._rtn}Read`] && child[`${this.hm._rtn}Read`][this.hm && _cn]) || parseIfInteger(this.parentId)
}, {
[_cn]: child[this.childForeignKey]
})
this.$emit('loadTableData')
if ((this.childListModal || this.isForm) && this.$refs.childList) {
this.$refs.childList.loadData()
await this.$refs.childList.loadData()
}
},
async editChild(child) {
@ -394,6 +411,7 @@ export default {
}
},
getCellValue(cellObj) {
console.log(cellObj)
if (cellObj) {
if (this.childMeta && this.childPrimaryCol) {
return cellObj[this.childPrimaryCol]

3
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

@ -1279,6 +1279,7 @@ class BaseModelSql extends BaseModel {
driver.union(
parent.map(p => {
const id =
p[_cn] ||
p[this.columnToAlias?.[this.pks[0].cn] || this.pks[0].cn] ||
p[this.pks[0].cn];
const query = driver(this.dbModels[child].tnPath)
@ -1296,7 +1297,7 @@ class BaseModelSql extends BaseModel {
const gs = _.groupBy(childs, _cn);
parent.forEach(row => {
row[`${this.dbModels?.[child]?._tn || child}List`] =
gs[row[this.pks[0]._cn]] || [];
gs[row[_cn] || row[this.pks[0]._cn]] || [];
});
}

Loading…
Cancel
Save