|
|
@ -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,23 +278,27 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
|
|
|
|
|
|
|
|
childColumn = await Column.get({ colId: id }); |
|
|
|
childColumn = await Column.get({ colId: id }); |
|
|
|
|
|
|
|
|
|
|
|
// create relation
|
|
|
|
// ignore relation creation if virtual
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', { |
|
|
|
if (!req.body.virtual) { |
|
|
|
childColumn: fkColName, |
|
|
|
// create relation
|
|
|
|
childTable: child.table_name, |
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', { |
|
|
|
parentTable: parent.table_name, |
|
|
|
childColumn: fkColName, |
|
|
|
onDelete: 'NO ACTION', |
|
|
|
childTable: child.table_name, |
|
|
|
onUpdate: 'NO ACTION', |
|
|
|
parentTable: parent.table_name, |
|
|
|
type: 'real', |
|
|
|
onDelete: 'NO ACTION', |
|
|
|
parentColumn: parent.primaryKey.column_name |
|
|
|
onUpdate: 'NO ACTION', |
|
|
|
}); |
|
|
|
type: 'real', |
|
|
|
|
|
|
|
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,26 +359,27 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
columns: associateTableCols |
|
|
|
columns: associateTableCols |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const rel1Args = { |
|
|
|
if (!req.body.virtual) { |
|
|
|
...req.body, |
|
|
|
const rel1Args = { |
|
|
|
childTable: aTn, |
|
|
|
...req.body, |
|
|
|
childColumn: parentCn, |
|
|
|
childTable: aTn, |
|
|
|
parentTable: parent.table_name, |
|
|
|
childColumn: parentCn, |
|
|
|
parentColumn: parentPK.column_name, |
|
|
|
parentTable: parent.table_name, |
|
|
|
type: 'real' |
|
|
|
parentColumn: parentPK.column_name, |
|
|
|
}; |
|
|
|
type: 'real' |
|
|
|
const rel2Args = { |
|
|
|
}; |
|
|
|
...req.body, |
|
|
|
const rel2Args = { |
|
|
|
childTable: aTn, |
|
|
|
...req.body, |
|
|
|
childColumn: childCn, |
|
|
|
childTable: aTn, |
|
|
|
parentTable: child.table_name, |
|
|
|
childColumn: childCn, |
|
|
|
parentColumn: childPK.column_name, |
|
|
|
parentTable: child.table_name, |
|
|
|
type: 'real' |
|
|
|
parentColumn: childPK.column_name, |
|
|
|
}; |
|
|
|
type: 'real' |
|
|
|
|
|
|
|
}; |
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel1Args); |
|
|
|
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel2Args); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel1Args); |
|
|
|
|
|
|
|
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 |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|