Skip to content

Commit 728a092

Browse files
committed
Fix multiple foreign keys not being exported in sqlite (#226)
1 parent 1a1fa05 commit 728a092

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/utils/exportSQL/sqlite.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function toSqlite(diagram) {
2929
.map((f) => `"${f.name}"`)
3030
.join(", ")})${inlineFK !== "" ? ",\n" : ""}`
3131
: ""
32-
}\t${inlineFK}\n);\n${table.indices
32+
}${inlineFK}\n);\n${table.indices
3333
.map(
3434
(i) =>
3535
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${
@@ -44,16 +44,17 @@ export function toSqlite(diagram) {
4444
}
4545

4646
export function getInlineFK(table, obj) {
47-
let fk = "";
47+
let fks = [];
4848
obj.references.forEach((r) => {
49-
if (fk !== "") return;
5049
if (r.startTableId === table.id) {
51-
fk = `FOREIGN KEY ("${table.fields[r.startFieldId].name}") REFERENCES "${
52-
obj.tables[r.endTableId].name
53-
}"("${
54-
obj.tables[r.endTableId].fields[r.endFieldId].name
55-
}")\n\tON UPDATE ${r.updateConstraint.toUpperCase()} ON DELETE ${r.deleteConstraint.toUpperCase()}`;
50+
fks.push(
51+
`\tFOREIGN KEY ("${table.fields[r.startFieldId].name}") REFERENCES "${
52+
obj.tables[r.endTableId].name
53+
}"("${
54+
obj.tables[r.endTableId].fields[r.endFieldId].name
55+
}")\n\tON UPDATE ${r.updateConstraint.toUpperCase()} ON DELETE ${r.deleteConstraint.toUpperCase()}`,
56+
);
5657
}
5758
});
58-
return fk;
59+
return fks.join(",\n");
5960
}

0 commit comments

Comments
 (0)