Fix multiple foreign keys not being exported in sqlite (#226)
This commit is contained in:
parent
1a1fa057cb
commit
728a092ac6
@ -29,7 +29,7 @@ export function toSqlite(diagram) {
|
|||||||
.map((f) => `"${f.name}"`)
|
.map((f) => `"${f.name}"`)
|
||||||
.join(", ")})${inlineFK !== "" ? ",\n" : ""}`
|
.join(", ")})${inlineFK !== "" ? ",\n" : ""}`
|
||||||
: ""
|
: ""
|
||||||
}\t${inlineFK}\n);\n${table.indices
|
}${inlineFK}\n);\n${table.indices
|
||||||
.map(
|
.map(
|
||||||
(i) =>
|
(i) =>
|
||||||
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${
|
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${
|
||||||
@ -44,16 +44,17 @@ export function toSqlite(diagram) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getInlineFK(table, obj) {
|
export function getInlineFK(table, obj) {
|
||||||
let fk = "";
|
let fks = [];
|
||||||
obj.references.forEach((r) => {
|
obj.references.forEach((r) => {
|
||||||
if (fk !== "") return;
|
|
||||||
if (r.startTableId === table.id) {
|
if (r.startTableId === table.id) {
|
||||||
fk = `FOREIGN KEY ("${table.fields[r.startFieldId].name}") REFERENCES "${
|
fks.push(
|
||||||
|
`\tFOREIGN KEY ("${table.fields[r.startFieldId].name}") REFERENCES "${
|
||||||
obj.tables[r.endTableId].name
|
obj.tables[r.endTableId].name
|
||||||
}"("${
|
}"("${
|
||||||
obj.tables[r.endTableId].fields[r.endFieldId].name
|
obj.tables[r.endTableId].fields[r.endFieldId].name
|
||||||
}")\n\tON UPDATE ${r.updateConstraint.toUpperCase()} ON DELETE ${r.deleteConstraint.toUpperCase()}`;
|
}")\n\tON UPDATE ${r.updateConstraint.toUpperCase()} ON DELETE ${r.deleteConstraint.toUpperCase()}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return fk;
|
return fks.join(",\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user