diff --git a/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue b/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue index 7f7eee36a8..3074f832db 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue @@ -20,6 +20,7 @@ @@ -485,7 +485,7 @@ export default { return this.$emit('saved') } if (this.isLookup && this.$refs.lookup) { - await this.$refs.lookup.save() + return await this.$refs.lookup.save() } this.newColumn.tn = this.nodes.tn diff --git a/packages/nc-gui/components/project/spreadsheet/components/editColumn/lookupOptions.vue b/packages/nc-gui/components/project/spreadsheet/components/editColumn/lookupOptions.vue index 66121c4527..c8ef2f6aa0 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/editColumn/lookupOptions.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/editColumn/lookupOptions.vue @@ -12,14 +12,14 @@ label="Child Table" :full-width="false" :items="refTables" - item-text="_tn" + item-text="_ltn" :item-value="v => v" :rules="[v => !!v || 'Required']" dense > @@ -35,7 +35,7 @@ label="Child column" :full-width="false" :items="columnList" - item-text="_cn" + item-text="_lcn" dense :loading="loadingColumns" :item-value="v => v" @@ -65,9 +65,46 @@ export default { refTables() { return this.meta ? [ - ...(this.meta.belongsTo || []).map(bt => ({ type: 'bt', relation: bt, tn: bt.rtn, _tn: bt._rtn })), - ...(this.meta.hasMany || []).map(hm => ({ type: 'hm', relation: hm, tn: hm.tn, _tn: hm._tn })), - ...(this.meta.manyToMany || []).map(mm => ({ type: 'mm', relation: mm, tn: mm.rtn, _tn: mm._rtn })) + ...(this.meta.belongsTo || []).map(({ rtn, _rtn, rcn, tn, cn }) => ({ + type: 'bt', + rtn, + _rtn, + rcn, + tn, + cn, + ltn: rtn, + _ltn: _rtn + })), + ...(this.meta.hasMany || []).map(({ + tn, + _tn, + cn, + rcn, + rtn + }) => ({ + type: 'hm', + tn, + _tn, + cn, + rcn, + rtn, + ltn: tn, + _ltn: _tn + })), + ...(this.meta.manyToMany || []).map(({ vtn, _vtn, vrcn, vcn, rtn, _rtn, rcn, tn, cn }) => ({ + type: 'mm', + tn, + cn, + vtn, + _vtn, + vrcn, + rcn, + rtn, + vcn, + _rtn, + ltn: rtn, + _ltn: _rtn + })) ] : [] }, @@ -76,18 +113,21 @@ export default { this.lookup && this.lookup.table && this.$store.state.meta.metas && - this.$store.state.meta.metas[this.lookup.table.tn] && - this.$store.state.meta.metas[this.lookup.table.tn].columns - ) || []).map(({ cn, _cn }) => ({ cn, _cn })) + this.$store.state.meta.metas[this.lookup.table.ltn] && + this.$store.state.meta.metas[this.lookup.table.ltn].columns + ) || []).map(({ cn, _cn }) => ({ + lcn: cn, + _lcn: _cn + })) } }, methods: { checkLookupExist(v) { return (this.lookup.table && (this.meta.v || []).every(c => !( - c.lookup && - c.type === this.lookup.table.type && - c.tn === this.lookup.table.tn && - c.cn === v.cn + c.lk && + c.lk.type === this.lookup.table.type && + c.lk.ltn === this.lookup.table.ltn && + c.lk.lcn === v.lcn ))) || 'Lookup already exist' }, async onTableChange() { @@ -97,7 +137,7 @@ export default { await this.$store.dispatch('meta/ActLoadMeta', { dbAlias: this.nodes.dbAlias, env: this.nodes.env, - tn: this.lookup.table.tn + tn: this.lookup.table.ltn }) } catch (e) { // ignore @@ -117,10 +157,11 @@ export default { const meta = JSON.parse(JSON.stringify(this.$store.state.meta.metas[this.meta.tn])) meta.v.push({ - // _cn: this.alias, - lookup: true, - ...this.lookup.table, - ...this.lookup.column + _cn: this.alias, + lk: { + ...this.lookup.table, + ...this.lookup.column + } }) await this.$store.dispatch('sqlMgr/ActSqlOp', [{ @@ -131,7 +172,7 @@ export default { meta }]) - return this.$emit('saved', `${this.lookup.column._cn} (from ${this.lookup.table._tn})`) + return this.$emit('saved', `${this.lookup.column._lcn} (from ${this.lookup.table._ltn})`) } catch (e) { this.$toast.error(e.message).goAway(3000) } diff --git a/packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue b/packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue index 2dd7eec33f..c5b61215bb 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/expandedForm.vue @@ -59,82 +59,86 @@ -
-
- - - -
-
- -
-
+
cl.cn === this.column.cn) || {})._cn + return (this.$store.state.meta.metas[this.column.lk.ltn].columns.find(cl => cl.cn === this.column.lk.lcn) || {})._cn }, localValueObj() { if (!this.column || !this.row) { return null } - switch (this.column.type) { + switch (this.column.lk.type) { case 'mm': - return this.row[`${this.column._tn}MMList`] + return this.row[`${this.column.lk._ltn}MMList`] case 'hm': - return this.row[`${this.column._tn}List`] + return this.row[`${this.column.lk._ltn}List`] case 'bt': - return this.row[`${this.column._tn}Read`] + return this.row[`${this.column.lk._ltn}Read`] default: return null } @@ -113,19 +103,19 @@ export default { return [this.localValueObj[this.lookUpColumnAlias]] }, queryParams() { - switch (this.column.type) { + switch (this.column.lk.type) { case 'bt': - return { where: `(${this.lookUpMeta.columns.find(c => c.cn === this.column.relation.rcn)._cn},eq,${this.row[this.meta.columns.find(c => c.cn === this.column.relation.cn)._cn]})` } + return { where: `(${this.lookUpMeta.columns.find(c => c.cn === this.column.lk.rcn)._cn},eq,${this.row[this.meta.columns.find(c => c.cn === this.column.lk.cn)._cn]})` } case 'hm': - return { where: `(${this.lookUpMeta.columns.find(c => c.cn === this.column.relation.cn)._cn},eq,${this.row[this.meta.columns.find(c => c.cn === this.column.relation.rcn)._cn]})` } + return { where: `(${this.lookUpMeta.columns.find(c => c.cn === this.column.lk.cn)._cn},eq,${this.row[this.meta.columns.find(c => c.cn === this.column.lk.rcn)._cn]})` } case 'mm': return this.assocMeta ? { conditionGraph: { [this.assocMeta.tn]: { relationType: 'hm', - [this.assocMeta.columns.find(c => c.cn === this.column.relation.vcn).cn]: { - eq: this.row[this.meta.columns.find(c => c.cn === this.column.relation.cn)._cn] + [this.assocMeta.columns.find(c => c.cn === this.column.lk.vcn).cn]: { + eq: this.row[this.meta.columns.find(c => c.cn === this.column.lk.cn)._cn] } } } @@ -145,14 +135,14 @@ export default { await this.$store.dispatch('meta/ActLoadMeta', { env: this.nodes.env, dbAlias: this.nodes.dbAlias, - tn: this.column.tn + tn: this.column.lk.ltn }) } - if (this.column.type === 'mm' && !this.assocMeta) { + if (this.column.lk.type === 'mm' && !this.assocMeta) { await this.$store.dispatch('meta/ActLoadMeta', { env: this.nodes.env, dbAlias: this.nodes.dbAlias, - tn: this.column.relation.vtn + tn: this.column.lk.vtn }) } }, diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue index 9bcbaacdb1..8d7ca27d7b 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualHeaderCell.vue @@ -11,9 +11,17 @@ mdi-table-network - - mdi-table-network - + @@ -31,7 +39,7 @@ - + mdi-pencil @@ -112,7 +120,7 @@ export default { }), computed: { alias() { - return this.column.lookup ? `${this.column._cn} (from ${this.column._tn})` : this.column._cn + return this.column.lk ? `${this.column.lk._lcn} (from ${this.column.lk._ltn})` : this.column._cn }, type() { if (this.column.bt) { @@ -184,8 +192,8 @@ export default { return `'${this.column.mm._tn}' & '${this.column.mm._rtn}' have
many to many relation` } else if (this.column.bt) { return `'${this.column.bt._tn}' belongs to '${this.column.bt._rtn}'` - } else if (this.column.lookup) { - return `'${this.column._cn}' from '${this.column._tn}' (${this.column.type}))` + } else if (this.column.lk) { + return `'${this.column.lk._lcn}' from '${this.column.lk._ltn}' (${this.column.lk.type})` } return '' } @@ -240,7 +248,7 @@ export default { } }, async deleteColumn() { - if (this.column.lookup) { + if (this.column.lk) { await this.deleteLookupColumn() } else { await this.deleteRelation() diff --git a/packages/nc-gui/components/project/spreadsheet/helpers/uiTypes.js b/packages/nc-gui/components/project/spreadsheet/helpers/uiTypes.js index 1733907bf1..d633dc0655 100644 --- a/packages/nc-gui/components/project/spreadsheet/helpers/uiTypes.js +++ b/packages/nc-gui/components/project/spreadsheet/helpers/uiTypes.js @@ -14,7 +14,7 @@ const uiTypes = [ }, { name: 'Lookup', - icon: 'mdi-link-variant' + icon: 'mdi-table-column-plus-before' }, { name: 'SingleLineText', diff --git a/packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js b/packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js index e508723bd2..9a9c28f625 100644 --- a/packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js +++ b/packages/nc-gui/components/project/spreadsheet/mixins/spreadsheet.js @@ -98,8 +98,8 @@ export default { { const _ref = {} columns.forEach((c) => { - if (c.virtual && c.lookup) { - c.alias = `${c._cn} (from ${c._tn})` + if (c.virtual && c.lk) { + c.alias = `${c.lk._lcn} (from ${c.lk._ltn})` } else { c.alias = c._cn } @@ -152,7 +152,7 @@ export default { // todo: handle if virtual column missing // construct fields args based on lookup columns const fieldsObj = ((this.meta && this.meta.v && this.meta.v) || []).reduce((obj, vc) => { - if (!vc.lookup) { + if (!vc.lk) { return obj } @@ -160,21 +160,21 @@ export default { let index let column - switch (vc.type) { + switch (vc.lk.type) { case 'mm': - index = nestedFields.mm.indexOf(vc.tn) + 1 + index = nestedFields.mm.indexOf(vc.lk.ltn) + 1 key = `mfields${index}` - column = vc.cn + column = vc.lk.lcn break case 'hm': - index = nestedFields.hm.indexOf(vc.tn) + 1 + index = nestedFields.hm.indexOf(vc.lk.ltn) + 1 key = `hfields${index}` - column = vc.cn + column = vc.lk.lcn break case 'bt': - index = nestedFields.bt.indexOf(vc.tn) + 1 + index = nestedFields.bt.indexOf(vc.lk.ltn) + 1 key = `bfields${index}` - column = vc.cn + column = vc.lk.lcn break } diff --git a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue index 42ba25ece0..3aca1b3c19 100644 --- a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue +++ b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue @@ -184,7 +184,7 @@ >
- + @@ -290,27 +291,17 @@ export default { }, style() { let style = '' - for (const [key, val] of Object.entries(this.columnsWidth || {})) { - if (val && key !== this.resizingCol) { - style += ` - [data-col="${key}"]{ - min-width: ${val}; - max-width: ${val}; - width: ${val}; - } - ` - } else if (key === this.resizingCol) { - style += ` - [data-col="${key}"]{ - min-width: ${this.resizingColWidth}; - max-width: ${this.resizingColWidth}; - width: ${this.resizingColWidth}; - } - ` + for (const c of this.availableColumns) { + const val = (this.columnsWidth && this.columnsWidth[c.alias]) || (c.virtual ? '200px' : (columnStyling[c.uidt] && columnStyling[c.uidt].w)) + if (val && c.key !== this.resizingCol) { + style += `[data-col="${c.alias}"]{min-width:${val};max-width:${val};width: ${val};}` } } return style + }, + resizeColStyle() { + return this.resizingCol ? ` [data-col="${this.resizingCol}"]{min-width:${this.resizingColWidth};max-width:${this.resizingColWidth};width:${this.resizingColWidth};}` : '' } }, watch: { @@ -344,20 +335,20 @@ export default { this.onCellValueChange(colIndex, rowIndex, columnObj) }, calculateColumnWidth() { - setTimeout(() => { - const obj = {} - this.meta && this.meta.columns && this.meta.columns.forEach((c) => { - obj[c._cn] = (columnStyling[c.uidt] && columnStyling[c.uidt].w) || undefined - }) - this.meta && this.meta.v && this.meta.v.forEach((v) => { - obj[v._cn] = v.bt ? '100px' : '200px' - }) - Array.from(this.$el.querySelectorAll('th')).forEach((el) => { - const width = el.getBoundingClientRect().width - obj[el.dataset.col] = obj[el.dataset.col] || ((width < 100 ? 100 : width) + 'px') - }) - this.$emit('update:columnsWidth', { ...obj, ...(this.columnWidth || {}) }) - }, 500) + // setTimeout(() => { + // const obj = {} + // this.meta && this.meta.columns && this.meta.columns.forEach((c) => { + // obj[c._cn] = (columnStyling[c.uidt] && columnStyling[c.uidt].w) || undefined + // }) + // this.meta && this.meta.v && this.meta.v.forEach((v) => { + // obj[v._cn] = v.bt ? '100px' : '200px' + // }) + // Array.from(this.$el.querySelectorAll('th')).forEach((el) => { + // const width = el.getBoundingClientRect().width + // obj[el.dataset.col] = obj[el.dataset.col] || ((width < 100 ? 100 : width) + 'px') + // }) + // this.$emit('update:columnsWidth', { ...obj, ...(this.columnWidth || {}) }) + // }, 2000) }, isCentrallyAligned(col) { return !['SingleLineText', @@ -372,7 +363,9 @@ export default { 'LastModifiedTime'].includes(col.uidt) }, async xcAuditModelCommentsCount() { - if (this.isPublicView || !this.data || !this.data.length) { return } + if (this.isPublicView || !this.data || !this.data.length) { + return + } const aggCount = await this.$store.dispatch('sqlMgr/ActSqlOp', [{ dbAlias: this.nodes.dbAlias }, 'xcAuditModelCommentsCount', { @@ -386,23 +379,33 @@ export default { }, onKeyDown(e) { - if (this.selected.col === null || this.selected.row === null) { return } + if (this.selected.col === null || this.selected.row === null) { + return + } switch (e.keyCode) { // left case 37: - if (this.selected.col > 0) { this.selected.col-- } + if (this.selected.col > 0) { + this.selected.col-- + } break // right case 39: - if (this.selected.col < this.colLength - 1) { this.selected.col++ } + if (this.selected.col < this.colLength - 1) { + this.selected.col++ + } break // up case 38: - if (this.selected.row > 0) { this.selected.row-- } + if (this.selected.row > 0) { + this.selected.row-- + } break // down case 40: - if (this.selected.row < this.rowLength - 1) { this.selected.row++ } + if (this.selected.row < this.rowLength - 1) { + this.selected.row++ + } break // enter case 13: @@ -424,7 +427,9 @@ export default { this.meta.columns && this.meta.columns[this.selected.col] && this.meta.columns[this.selected.col].virtual - ) { return } + ) { + return + } this.selected.col = null this.selected.row = null }, @@ -452,7 +457,9 @@ export default { } }, makeEditable(col, row) { - if (this.isPublicView || !this.isEditable) { return } + if (this.isPublicView || !this.isEditable) { + return + } if (this.availableColumns[col].ai) { return this.$toast.info('Auto Increment field is not editable').goAway(3000) } @@ -777,8 +784,4 @@ th:first-child, td:first-child { transform: rotate(90deg); } -th { - min-width: 100px; -} - diff --git a/packages/nc-gui/plugins/globalMixin.js b/packages/nc-gui/plugins/globalMixin.js index c7497eee16..dd5b61e117 100644 --- a/packages/nc-gui/plugins/globalMixin.js +++ b/packages/nc-gui/plugins/globalMixin.js @@ -48,8 +48,6 @@ export default async({ store }) => { el.appendChild(resizer) resizer.addEventListener('mousedown', initDrag, false) - el.style.transition = '20ms width0' - // eslint-disable-next-line no-unused-vars let startX, startY, startWidth @@ -76,10 +74,8 @@ export default async({ store }) => { function doDrag(e) { width = (startWidth + e.clientX - startX) + 'px' - el.style.maxWidth = el.style.minWidth = el.style.width = width + el.style.width = width emit(vnode, 'xcresizing', width) - // - // p.style.height = (startHeight + e.clientY - startY) + 'px'; } function stopDrag(e) { diff --git a/packages/nc-gui/plugins/ncApis/index.js b/packages/nc-gui/plugins/ncApis/index.js index d264213714..8f7491a5e4 100644 --- a/packages/nc-gui/plugins/ncApis/index.js +++ b/packages/nc-gui/plugins/ncApis/index.js @@ -5,7 +5,7 @@ export default function({ store: $store, $axios, ...rest }, inject) { let projectId = null inject('ncApis', { - get: ({ table, dbAlias, env }) => { + get: ({ table, dbAlias = 'db', env = 'dev' }) => { if (!$store.state.meta.metas[table]) { return } diff --git a/packages/nocodb/package-lock.json b/packages/nocodb/package-lock.json index 4c32b33a2b..91d1f8deef 100644 --- a/packages/nocodb/package-lock.json +++ b/packages/nocodb/package-lock.json @@ -1,6 +1,6 @@ { "name": "nocodb", - "version": "0.11.1", + "version": "0.11.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -11800,9 +11800,9 @@ "integrity": "sha512-3AryS9uwa5NfISLxMciUonrH7YfXp+nlahB9T7girXIsLQrmwX4MdnuKs32akduCOGpKmjTJSWmATULbuMkbfw==" }, "nc-help": { - "version": "0.2.7", - "resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.7.tgz", - "integrity": "sha512-31wxoJmfZHJ4aP/YiI+GgZRqwulyB6Z5BamcCUw/NDdNVoze+zHX0CtmoxfSlyi/U4zUOG9rhennKPv6QmmsMQ==", + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.8.tgz", + "integrity": "sha512-h6HUWb2trYEVm7x2/hWxifeq+ZALCIFxZFISgpI/IQPhe/BSoGUNpcRIhWg8wt1y87kxZ7/VCkvTQUhW9OTOGg==", "requires": { "axios": "^0.21.1", "boxen": "^4.2.0", diff --git a/packages/nocodb/package.json b/packages/nocodb/package.json index dcced24239..d4908b8a4e 100644 --- a/packages/nocodb/package.json +++ b/packages/nocodb/package.json @@ -144,7 +144,7 @@ "mysql2": "^2.2.5", "nanoid": "^3.1.20", "nc-common": "0.0.6", - "nc-help": "^0.2.7", + "nc-help": "^0.2.8", "nc-lib-gui": "^0.2.9", "nc-plugin": "^0.1.1", "nodemailer": "^6.4.10", diff --git a/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts b/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts index 58af3d5856..a7c6fa8398 100644 --- a/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts +++ b/packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts @@ -474,10 +474,10 @@ export default abstract class BaseApiBuilder implements XcDynami // update lookup columns this.metas[bt.rtn].v?.forEach(v => { - if (v.tn === tn && v.cn === column.cno) { + if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cno) { relationTableMetas.add(this.metas[bt.rtn]) - v.cn = column.cn; - v._cn = column._cn; + v.lk.lcn = column.cn; + v.lk._lcn = column._cn; } }) } @@ -503,10 +503,10 @@ export default abstract class BaseApiBuilder implements XcDynami // update lookup columns this.metas[hm.tn].v?.forEach(v => { - if (v.tn === tn && v.cn === column.cno) { + if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cno) { relationTableMetas.add(this.metas[hm.tn]) - v.cn = column.cn; - v._cn = column._cn; + v.lk.lcn = column.cn; + v.lk._lcn = column._cn; } }) @@ -533,10 +533,10 @@ export default abstract class BaseApiBuilder implements XcDynami // update lookup columns this.metas[mm.rtn].v?.forEach(v => { - if (v.tn === tn && v.cn === column.cno) { + if (v.lk &&v.lk.ltn === tn && v.lk.lcn === column.cno) { relationTableMetas.add(this.metas[mm.tn]) - v.cn = column.cn; - v._cn = column._cn; + v.lk.lcn = column.cn; + v.lk._lcn = column._cn; } }) @@ -598,7 +598,7 @@ export default abstract class BaseApiBuilder implements XcDynami for (const bt of newMeta.belongsTo) { // filter out lookup columns which maps to current col this.metas[bt.rtn].v = this.metas[bt.rtn].v?.filter(v => { - if (v.lookup && v.tn === tn && v.cn === column.cn) { + if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cn) { relationTableMetas.add(this.metas[bt.rtn]) return false; } @@ -613,7 +613,7 @@ export default abstract class BaseApiBuilder implements XcDynami for (const hm of newMeta.hasMany) { // filter out lookup columns which maps to current col this.metas[hm.tn].v = this.metas[hm.tn].v?.filter(v => { - if (v.lookup && v.tn === tn && v.cn === column.cn) { + if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cn) { relationTableMetas.add(this.metas[hm.tn]) return false; } @@ -627,7 +627,7 @@ export default abstract class BaseApiBuilder implements XcDynami for (const mm of newMeta.manyToMany) { // filter out lookup columns which maps to current col this.metas[mm.rtn].v=this.metas[mm.rtn].v?.filter(v => { - if (v.tn === tn && v.rcn === column.cn) { + if (v.lk && v.lk.ltn === tn && v.lk.lcn === column.cn) { relationTableMetas.add(this.metas[mm.tn]) return false; } @@ -904,11 +904,11 @@ export default abstract class BaseApiBuilder implements XcDynami // filter lookup and relation virtual columns parentMeta.v = parentMeta.v.filter(({mm, ...rest}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) // check for lookup - && !(rest.type === 'mm' && (rest.relation.tn === parent && rest.relation.rtn === child || rest.relation.tn === child && rest.relation.rtn === parent)) + && !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent)) ) childMeta.v = childMeta.v.filter(({mm, ...rest}) => (!mm || !(mm.tn === parent && mm.rtn === child || mm.tn === child && mm.rtn === parent)) // check for lookup - && !(rest.type === 'mm' && (rest.relation.tn === parent && rest.relation.rtn === child || rest.relation.tn === child && rest.relation.rtn === parent)) + && !(rest.lk && rest.lk.type === 'mm' && (rest.lk.tn === parent && rest.lk.rtn === child || rest.lk.tn === child && rest.lk.rtn === parent)) ) for (const meta of [parentMeta, childMeta]) { diff --git a/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts b/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts index be39e6776e..7df310e512 100644 --- a/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts +++ b/packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts @@ -1380,8 +1380,8 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr { const oldMeta = JSON.parse(existingModel.meta); Object.assign(oldMeta, { hasMany: meta.hasMany, - v: oldMeta.v.filter(({hm, lookup, relation, type}) => (!hm || hm.rtn !== tnp || hm.tn !== tnc) && - !(lookup && relation && type === 'hm' && relation.rtn === tnp && relation.tn === tnc)) + v: oldMeta.v.filter(({hm, lk}) => (!hm || hm.rtn !== tnp || hm.tn !== tnc) && + !(lk && lk.type === 'hm' && lk.rtn === tnp && lk.tn === tnc)) }); // todo: backup schema await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { @@ -1430,8 +1430,8 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr { const oldMeta = JSON.parse(existingModel.meta); Object.assign(oldMeta, { belongsTo: meta.belongsTo, - v: oldMeta.v.filter(({bt, lookup, relation, type}) => (!bt || bt.rtn !== tnp || bt.tn !== tnc) && - !(lookup && relation && type === 'bt' && relation.rtn === tnp && relation.tn === tnc)) + v: oldMeta.v.filter(({bt, lk}) => (!bt || bt.rtn !== tnp || bt.tn !== tnc) && + !(lk && lk.type === 'bt' && lk.rtn === tnp && lk.tn === tnc)) }); await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { title: tnc, @@ -1963,3 +1963,5 @@ export class GqlApiBuilder extends BaseApiBuilder implements XcMetaMgr { * along with this program. If not, see . * */ + + diff --git a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts index cbc4e63009..9b4d33fa3f 100644 --- a/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts +++ b/packages/nocodb/src/lib/noco/rest/RestApiBuilder.ts @@ -1,4 +1,3 @@ - import fs from 'fs'; import path from 'path'; @@ -34,7 +33,7 @@ const log = debug('nc:api:rest'); const NC_CUSTOM_ROUTE_KEY = '__xc_custom'; export class RestApiBuilder extends BaseApiBuilder { - public readonly type='rest'; + public readonly type = 'rest'; private controllers: { [key: string]: RestCtrlBelongsTo | RestCtrl | RestCtrlHasMany | RestCtrlCustom }; private procedureCtrl: RestCtrlProcedure; private routers: { [key: string]: Router }; @@ -602,7 +601,7 @@ export class RestApiBuilder extends BaseApiBuilder { public async onTableCreate(tn: string, args?: any): Promise { - await super.onTableCreate(tn,args); + await super.onTableCreate(tn, args); const columns = args.columns ? { [tn]: args.columns?.map(({altered: _al, ...rest}) => rest) @@ -1215,8 +1214,8 @@ export class RestApiBuilder extends BaseApiBuilder { const oldMeta = JSON.parse(existingModel.meta); Object.assign(oldMeta, { hasMany: meta.hasMany, - v: oldMeta.v.filter(({hm, lookup, relation, type}) => (!hm || hm.rtn !== tnp || hm.tn !== tnc) && - !(lookup && relation && type==='hm'&&relation.rtn === tnp && relation.tn === tnc )) + v: oldMeta.v.filter(({hm, lk}) => (!hm || hm.rtn !== tnp || hm.tn !== tnc) && + !(lk && lk.type === 'hm' && lk.rtn === tnp && lk.tn === tnc)) }); // todo: delete from query_params @@ -1252,8 +1251,8 @@ export class RestApiBuilder extends BaseApiBuilder { Object.assign(oldMeta, { belongsTo: meta.belongsTo, - v: oldMeta.v.filter(({bt, relation, lookup,type}) => (!bt || bt.rtn !== tnp || bt.tn !== tnc) && - !(lookup && relation && type==='bt'&&relation.rtn === tnp && relation.tn === tnc )) + v: oldMeta.v.filter(({bt, lk}) => (!bt || bt.rtn !== tnp || bt.tn !== tnc) && + !(lk && lk.type === 'bt' && lk.rtn === tnp && lk.tn === tnc)) }); // todo: delete from query_params await this.xcMeta.metaUpdate(this.projectId,