|
|
|
@ -45,6 +45,7 @@ async function createHmAndBtColumn(
|
|
|
|
|
childColumn: Column, |
|
|
|
|
type?: RelationTypes, |
|
|
|
|
alias?: string, |
|
|
|
|
virtual = false, |
|
|
|
|
isSystemCol = false |
|
|
|
|
) { |
|
|
|
|
// save bt column
|
|
|
|
@ -65,6 +66,7 @@ async function createHmAndBtColumn(
|
|
|
|
|
fk_child_column_id: childColumn.id, |
|
|
|
|
fk_parent_column_id: parent.primaryKey.id, |
|
|
|
|
fk_related_model_id: parent.id, |
|
|
|
|
virtual, |
|
|
|
|
system: isSystemCol |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -82,6 +84,7 @@ async function createHmAndBtColumn(
|
|
|
|
|
fk_child_column_id: childColumn.id, |
|
|
|
|
fk_parent_column_id: parent.primaryKey.id, |
|
|
|
|
fk_related_model_id: child.id, |
|
|
|
|
virtual, |
|
|
|
|
system: isSystemCol |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -275,6 +278,8 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
|
|
|
|
|
|
|
|
|
|
childColumn = await Column.get({ colId: id }); |
|
|
|
|
|
|
|
|
|
// ignore relation creation if virtual
|
|
|
|
|
if (!req.body.virtual) { |
|
|
|
|
// create relation
|
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', { |
|
|
|
|
childColumn: fkColName, |
|
|
|
@ -286,12 +291,14 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
|
|
|
|
|
parentColumn: parent.primaryKey.column_name |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
await createHmAndBtColumn( |
|
|
|
|
child, |
|
|
|
|
parent, |
|
|
|
|
childColumn, |
|
|
|
|
req.body.type, |
|
|
|
|
req.body.title |
|
|
|
|
req.body.title, |
|
|
|
|
req.body.virtual |
|
|
|
|
); |
|
|
|
|
} else if (req.body.type === 'mm') { |
|
|
|
|
const aTn = `${project?.prefix ?? ''}_nc_m2m_${randomID()}`; |
|
|
|
@ -352,6 +359,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
|
|
|
|
|
columns: associateTableCols |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (!req.body.virtual) { |
|
|
|
|
const rel1Args = { |
|
|
|
|
...req.body, |
|
|
|
|
childTable: aTn, |
|
|
|
@ -371,7 +379,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
|
|
|
|
|
|
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel1Args); |
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel2Args); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
const parentCol = (await assocModel.getColumns())?.find( |
|
|
|
|
c => c.column_name === parentCn |
|
|
|
|
); |
|
|
|
@ -385,6 +393,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
|
|
|
|
|
childCol, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
req.body.virtual, |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
await createHmAndBtColumn( |
|
|
|
@ -393,6 +402,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
|
|
|
|
|
parentCol, |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
req.body.virtual, |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|