diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue index a3b81a0fb7..c364688ffd 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue @@ -34,7 +34,10 @@ :primary-col="parentPrimaryCol" :primary-key="parentPrimaryKey" :api="parentApi" - :query-params="parentQueryParams" + :query-params="{ + ...parentQueryParams, + where: isNew ? null :`${btWhereClause}`, + }" :is-public="isPublic" :tn="bt && bt.rtn" :password="password" @@ -106,6 +109,7 @@ import ListItems from '@/components/project/spreadsheet/components/virtualCell/components/listItems' import ListChildItems from '@/components/project/spreadsheet/components/virtualCell/components/listChildItems' import ItemChip from '~/components/project/spreadsheet/components/virtualCell/components/itemChip' +import { parseIfInteger } from '@/helpers' export default { name: 'BelongsToCell', @@ -173,6 +177,20 @@ export default { parentPrimaryKey() { return this.parentMeta && (this.parentMeta.columns.find(c => c.pk) || {})._cn }, + parentReferenceKey() { + return this.parentMeta && (this.parentMeta.columns.find(c => c.cn === this.bt.rcn) || {})._cn + }, + btWhereClause() { + // if parent reference key is pk, then filter out the selected value + // else, filter out the selected value + empty values (as we can't set an empty value) + const prk = this.parentReferenceKey + const isPk = !!(this.parentMeta && (this.parentMeta.columns.find(c => c.pk && c._cn === prk))) || false + let selectedValue = this.meta && this.meta.columns ? this.meta.columns.filter(c => c.cn === this.bt.cn).map(c => this.row[c._cn] || '').join('___') : '' + if (this.parentMeta && (this.parentMeta.columns.find(c => c._cn === prk)).type !== 'string') { + selectedValue = selectedValue || 0 + } + return `(${prk},not,${selectedValue})` + (!isPk ? `~and(${prk},not,)` : '') + }, parentQueryParams() { if (!this.parentMeta) { return {} @@ -211,7 +229,7 @@ export default { return Object.values(this.value || this.localState)[1] } return null - } + }, }, watch: { isNew(n, o) { @@ -319,11 +337,11 @@ export default { 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 + // let isNum = false - if (pkColumns.length === 1) { - isNum = ['float', 'integer'].includes(this.sqlUi.getAbstractType(pkColumns[0])) - } + // if (pkColumns.length === 1) { + // isNum = ['float', 'integer'].includes(this.sqlUi.getAbstractType(pkColumns[0])) + // } if (this.isNew) { this.localState = parent @@ -332,9 +350,8 @@ export default { this.newRecordModal = false return } - await this.api.update(id, { - [_cn]: isNum ? +pid : pid + [_cn]: parseIfInteger(parent[this.parentReferenceKey]) }, { [_cn]: this.value && this.value[this.parentPrimaryKey] }) @@ -413,6 +430,7 @@ export default { * @author Naveen MR * @author Pranav C Balan * @author Md Ishtiaque Zafar + * @author Wing-Kam Wong * * @license GNU AGPL version 3 or any later version * diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue index 14e001e02f..efb541955b 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue @@ -151,7 +151,10 @@ export default { if (!this.api) { return } - + const isByPass = this.queryParams.isByPass || false + if (isByPass) { + return + } let where = this.queryParams.where || '' if (this.query) { where += (where ? '~and' : '') + `(${this.primaryCol},like,%${this.query}%)` 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 43cbf9a830..b6c6a21c45 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue @@ -2,7 +2,7 @@