Browse Source

fix: one-to-one relation in nested add new row option

pull/8399/head
Pranav C 7 months ago
parent
commit
3195d88c82
  1. 4
      packages/nc-gui/components/virtual-cell/OneToOne.vue
  2. 2
      packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue
  3. 9
      packages/nocodb/src/db/BaseModelSqlv2.ts

4
packages/nc-gui/components/virtual-cell/OneToOne.vue

@ -55,7 +55,9 @@ const value = computed(() => {
if (cellValue?.value) {
return cellValue?.value
} else if (isNew.value) {
return state?.value?.[column?.value.title as string]
return Array.isArray(state?.value?.[column?.value.title as string])
? state?.value?.[column?.value.title as string][0]
: state?.value?.[column?.value.title as string]
}
return null
})

2
packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue

@ -142,7 +142,7 @@ const newRowState = computed(() => {
const relatedTableColOpt = colInRelatedTable?.colOptions as LinkToAnotherRecordType
if (!relatedTableColOpt) return {}
if (relatedTableColOpt.type === RelationTypes.BELONGS_TO) {
if (relatedTableColOpt.type === RelationTypes.BELONGS_TO || relatedTableColOpt.type === RelationTypes.ONE_TO_ONE) {
return {
[colInRelatedTable.title as string]: row?.value?.row,
}

9
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -3314,16 +3314,17 @@ class BaseModelSqlv2 {
await childModel.getColumns();
if (isBt) {
// if array then extract value from first element
const colVal = Array.isArray(nestedData)
? nestedData[0]?.[childModel.primaryKey.title]
: nestedData[childModel.primaryKey.title];
// todo: unlink the ref record
preInsertOps.push(async () => {
return this.dbDriver(this.getTnPath(childModel.table_name))
.update({
[childCol.column_name]: null,
})
.where(
childCol.column_name,
nestedData[childModel.primaryKey.title],
)
.where(childCol.column_name, colVal)
.toQuery();
});

Loading…
Cancel
Save