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}"> <div class="d-flex d-100 chips-wrapper" :class="{active}">
<template v-if="!isForm"> <template v-if="!isForm">
<div class="chips d-flex align-center img-container flex-grow-1 hm-items"> <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 <item-chip
v-for="(ch,i) in (value|| localState)" v-for="(ch,i) in (value|| localState)"
:key="i" :key="i"
@ -54,7 +54,7 @@
:parent-meta="meta" :parent-meta="meta"
:query-params="{ :query-params="{
...childQueryParams, ...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" :is-public="isPublic"
:password="password" :password="password"
@ -80,7 +80,7 @@
:column="column" :column="column"
:query-params="{ :query-params="{
...childQueryParams, ...childQueryParams,
where: `(${childForeignKey},eq,${parentId})` where: `(${childForeignKey},eq,${childForeignKeyVal != '' ? childForeignKeyVal : parentId})`
}" }"
:is-public="isPublic" :is-public="isPublic"
:row-id="parentId" :row-id="parentId"
@ -252,6 +252,9 @@ export default {
}, },
parentId() { parentId() {
return this.meta && this.meta.columns ? this.meta.columns.filter(c => c.pk).map(c => this.row[c._cn]).join('___') : '' 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: { watch: {
@ -347,7 +350,10 @@ export default {
this.newRecordModal = true this.newRecordModal = true
}, },
async addChildToParent(child) { async addChildToParent(child) {
console.log("invoking addChildToParent ...")
console.log(child)
if (this.isNew && this.localState.every(it => it[this.childForeignKey] !== child[this.childPrimaryKey])) { if (this.isNew && this.localState.every(it => it[this.childForeignKey] !== child[this.childPrimaryKey])) {
console.log(child)
this.localState.push(child) this.localState.push(child)
this.$emit('update:localState', [...this.localState]) this.$emit('update:localState', [...this.localState])
this.$emit('saveRow') this.$emit('saveRow')
@ -359,15 +365,26 @@ export default {
const _cn = this.childForeignKey const _cn = this.childForeignKey
this.newRecordModal = false 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, { 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] [_cn]: child[this.childForeignKey]
}) })
this.$emit('loadTableData') this.$emit('loadTableData')
if ((this.childListModal || this.isForm) && this.$refs.childList) { if ((this.childListModal || this.isForm) && this.$refs.childList) {
this.$refs.childList.loadData() await this.$refs.childList.loadData()
} }
}, },
async editChild(child) { async editChild(child) {
@ -394,6 +411,7 @@ export default {
} }
}, },
getCellValue(cellObj) { getCellValue(cellObj) {
console.log(cellObj)
if (cellObj) { if (cellObj) {
if (this.childMeta && this.childPrimaryCol) { if (this.childMeta && this.childPrimaryCol) {
return cellObj[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( driver.union(
parent.map(p => { parent.map(p => {
const id = const id =
p[_cn] ||
p[this.columnToAlias?.[this.pks[0].cn] || this.pks[0].cn] || p[this.columnToAlias?.[this.pks[0].cn] || this.pks[0].cn] ||
p[this.pks[0].cn]; p[this.pks[0].cn];
const query = driver(this.dbModels[child].tnPath) const query = driver(this.dbModels[child].tnPath)
@ -1296,7 +1297,7 @@ class BaseModelSql extends BaseModel {
const gs = _.groupBy(childs, _cn); const gs = _.groupBy(childs, _cn);
parent.forEach(row => { parent.forEach(row => {
row[`${this.dbModels?.[child]?._tn || child}List`] = row[`${this.dbModels?.[child]?._tn || child}List`] =
gs[row[this.pks[0]._cn]] || []; gs[row[_cn] || row[this.pks[0]._cn]] || [];
}); });
} }

Loading…
Cancel
Save