Closed cbadger85 closed 2 years ago
Which version of krush are you using? I made some changes for self-reference-support a while ago, but I am not sure whether that is in a release yet. Though I didn't test the combination of self-references + bidir, so that might be a problem.
Guys, any updates? Considering to use krush, but that bug could be a blocker for that
Recursive structures are not supported for now, krush needs to know what to load in advance. There is a Tree example here : https://github.com/TouK/krush/blob/master/example/src/main/kotlin/pl/touk/krush/one2many/bidi/Tree.kt when you keep all the levels of structure in different entities - you'd have to divide your model eg. ParentCategory, Category, SubCategory.
Hi, This is now addressed in 0.6.0 release by using aliases:
val parentAlias = CategoryTable.alias("parent")
val categories =
CategoryTable.join(parentAlias, JoinType.LEFT, CategoryTable.parentId, parentAlias[CategoryTable.id])
.selectAll()
.map { it.toCategory(parentAlias) }
Full example: https://github.com/TouK/krush/blob/master/example/src/test/kotlin/pl/touk/krush/realreferences/CategoryTest.kt
When attempting to create self referencing entities, the app fails to build because the generated code creates an invalid
getOrNull
method.example:
generates:
The issue is here
mapValues { (_, category) -> category.copy(category = category) }
, where the copy method is using acategory
parameter that doesn't exist. I believe the proper code should bemapValues { (_, category) -> category.copy(parent = category) }
.Any help would be appreciated!
EDIT: Actually, it seems like any self-referenced parent-child entity causes problems. I tried this code to use a join table instead and got a
error: Exception while building entity graph: java.lang.NullPointerException