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