increment table alias, when multiple tables used

This commit is contained in:
Jan Prochazka
2022-01-05 12:31:26 +01:00
parent c4aa63eab5
commit c0dc179140

View File

@@ -18,7 +18,7 @@
export let onChange; export let onChange;
export let conid; export let conid;
export let database; export let database;
export let menu; export let menu;
let domCanvas; let domCanvas;
@@ -163,6 +163,7 @@
left: fromTable.left + 300, left: fromTable.left + 300,
top: fromTable.top + 50, top: fromTable.top + 50,
designerId: newTableDesignerId, designerId: newTableDesignerId,
alias: getNewTableAlias(toTable, current.tables),
}, },
], ],
references: [ references: [
@@ -196,6 +197,14 @@
); );
}; };
const getNewTableAlias = (table, tables) => {
const usedAliases = (tables || []).map(x => x.alias || x.pureName);
if (!usedAliases.includes(table.pureName)) return null;
let index = 2;
while (usedAliases.includes(`${table.pureName}${index}`)) index += 1;
return `${table.pureName}${index}`;
};
const handleChangeColumn = (column, changeFunc) => { const handleChangeColumn = (column, changeFunc) => {
callChange(current => { callChange(current => {
const currentColumns = (current || {}).columns || []; const currentColumns = (current || {}).columns || [];
@@ -258,7 +267,13 @@
return { return {
...current, ...current,
tables: [...((current || {}).tables || []), json], tables: [
...((current || {}).tables || []),
{
...json,
alias: getNewTableAlias(json, current?.tables),
},
],
references: references:
foreignKeys.length == 1 foreignKeys.length == 1
? [ ? [