From dc81004163e3fb541b444aaec7436f42852a08b3 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 24 Feb 2022 14:27:54 +0800 Subject: [PATCH] wip: revise bypass logic Signed-off-by: Wing-Kam Wong --- .../components/virtualCell/hasManyCell.vue | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue index e452758d23..f63cec4214 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue @@ -54,9 +54,9 @@ :parent-meta="meta" :query-params="{ ...childQueryParams, - // return empty set if childForeignKeyVal is empty - // to avoid foreign key constraint violation in real relation - isByPass: !isVirtualRelation && childForeignKeyVal === '', + // check if it needs to bypass to + // avoid foreign key constraint violation in real relation + isByPass, where: // show all for new record isNew ? null : @@ -225,17 +225,31 @@ export default { return this.meta && (this.meta.columns.find(c => c.pv) || {})._cn }, childPrimaryKey() { + console.log('childPrimaryKey= ' + (this.childMeta && (this.childMeta.columns.find(c => c.pk) || {})._cn)) return this.childMeta && (this.childMeta.columns.find(c => c.pk) || {})._cn }, childForeignKey() { + console.log('childForeignKey= ' + (this.childMeta && (this.childMeta.columns.find(c => c.cn === this.hm.cn) || {})._cn)) return this.childMeta && (this.childMeta.columns.find(c => c.cn === this.hm.cn) || {})._cn }, childForeignKeyVal() { + console.log('childForeignKeyVal: ' + (this.meta && this.meta.columns ? this.meta.columns.filter(c => c._cn === this.childForeignKey).map(c => this.row[c._cn] || '').join('___') : '')) return this.meta && this.meta.columns ? this.meta.columns.filter(c => c._cn === this.childForeignKey).map(c => this.row[c._cn] || '').join('___') : '' }, isVirtualRelation() { return (this.childMeta && (!!this.childMeta.columns.find(c => c.cn === this.hm.cn && this.hm.type === 'virtual'))) || false }, + isByPass() { + if (this.isVirtualRelation) { + return false + } + // if child fk references a column in parent which is not pk, + // then this column has to be filled + if (((this.meta && this.meta.columns.find(c => !c.pk && c.cn === this.hm.rcn)) || false)) { + return this.childForeignKeyVal === '' + } + return false + }, disabledChildColumns() { return { [this.childForeignKey]: true } }, @@ -512,6 +526,7 @@ export default { * * @author Naveen MR * @author Pranav C Balan + * @author Wing-Kam Wong * * @license GNU AGPL version 3 or any later version *