Browse Source

fix: Bug with M2M relation delete

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/498/head
Pranav C 3 years ago
parent
commit
6e6bc9206c
  1. 5
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts
  2. 2
      packages/nocodb/src/lib/noco/common/NcConnectionMgr.ts
  3. 5
      packages/nocodb/src/lib/noco/common/XcMigrationSource.ts
  4. 7
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  5. 42
      packages/nocodb/src/lib/noco/migrations/nc_003_add_fkn_column.ts

5
packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts

@ -218,7 +218,8 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
onDelete,
onUpdate,
parentColumn,
virtual
virtual,
foreignKeyName: fkn
} = args;
XcCache.del([this.projectId, this.dbAlias, 'table', tnp].join('::'));
@ -236,6 +237,7 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
db_type: this.connectionConfig?.client,
dr: onDelete,
ur: onUpdate,
fkn
})
} else {
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_relations', {
@ -248,7 +250,6 @@ export default abstract class BaseApiBuilder<T extends Noco> implements XcDynami
rcn: parentColumn,
})
}
Tele.emit('evt', {evt_type: 'relation:created'})
}

2
packages/nocodb/src/lib/noco/common/NcConnectionMgr.ts

@ -5,6 +5,7 @@ import Knex from "knex";
import {SqlClientFactory} from 'nc-help';
import NcMetaIO from "../meta/NcMetaIO";
import {defaultConnectionConfig} from "../../utils/NcConfigFactory";
export default class NcConnectionMgr {
private static connectionRefs: {
@ -92,6 +93,7 @@ export default class NcConnectionMgr {
{
...connectionConfig,
connection: {
...defaultConnectionConfig,
...connectionConfig.connection,
typeCast(_field, next) {
const res = next();

5
packages/nocodb/src/lib/noco/common/XcMigrationSource.ts

@ -1,5 +1,6 @@
import * as project from '../migrations/nc_001_init';
import * as m2m from '../migrations/nc_002_add_m2m';
import * as fkn from '../migrations/nc_003_add_fkn_column';
// Create a custom migration source class
export default class XcMigrationSource{
@ -8,7 +9,7 @@ export default class XcMigrationSource{
// arguments to getMigrationName and getMigration
public getMigrations(): Promise<any> {
// In this example we are just returning migration names
return Promise.resolve(['project','m2m'])
return Promise.resolve(['project','m2m', 'fkn'])
}
public getMigrationName(migration): string {
@ -21,6 +22,8 @@ export default class XcMigrationSource{
return project;
case 'm2m':
return m2m;
case 'fkn':
return fkn;
}
}
}

7
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -2529,7 +2529,7 @@ export default class NcMetaMgr {
}
});
}
const outrel1 = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('relationCreate', {
const outrel1 = await this.projectMgr.getSqlMgr({id: projectId}).handleRequest('n', {
...args,
args: rel2Args
});
@ -2616,7 +2616,8 @@ export default class NcMetaMgr {
childColumn: relation.cn,
childTable: relation.tn,
parentTable: relation.rtn,
parentColumn: relation.rcn
parentColumn: relation.rcn,
foreignKeyName: relation.fkn
},
api: 'relationDelete',
sqlOpPlus: true,
@ -2683,6 +2684,7 @@ export default class NcMetaMgr {
parentColumn: rel1.rcn,
childTable: rel1.tn,
childColumn: rel1.cn,
foreignKeyName: rel1.fkn,
type: 'bt',
}
}, req, false)
@ -2693,6 +2695,7 @@ export default class NcMetaMgr {
parentColumn: rel2.rcn,
childTable: rel2.tn,
childColumn: rel2.cn,
foreignKeyName: rel2.fkn,
type: 'bt',
}
}, req, false);

42
packages/nocodb/src/lib/noco/migrations/nc_003_add_fkn_column.ts

@ -0,0 +1,42 @@
import Knex from "knex";
const up = async (knex: Knex) => {
await knex.schema.alterTable('nc_relations', table => {
table.string('fkn');
})
};
const down = async (knex) => {
await knex.schema.alterTable('nc_relations', table => {
table.dropColumns('fkn');
})
};
export {
up, down
}
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
*
* @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
Loading…
Cancel
Save