Skip to content

Commit 40d9fe5

Browse files
committed
handle self referencing relations
1 parent c482d23 commit 40d9fe5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

typo/src/scala/typo/internal/ComputedTable.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ case class ComputedTable(
1515
val source = Source.Table(dbTable.name)
1616
val pointsTo: Map[db.ColName, (Source.Relation, db.ColName)] =
1717
dbTable.foreignKeys.flatMap { fk =>
18-
val otherTable: Lazy[HasSource] = eval(fk.otherTable)
19-
val value = fk.otherCols.map(cn => (otherTable.forceGet.source, cn))
18+
val otherTable: HasSource =
19+
if (fk.otherTable == dbTable.name) this
20+
else eval(fk.otherTable).forceGet(s"${dbTable.name.value} => ${fk.otherTable.value}")
21+
22+
val value = fk.otherCols.map(cn => (otherTable.source, cn))
2023
fk.cols.zip(value).toList
2124
}.toMap
2225

0 commit comments

Comments
 (0)