如何在Jooq两次与同一张桌子一起加入?
我有与另一个有一对一关系的表,但是其中有两个,SRC和DST,如何加入它吧?我做了这样的事情,但不确定这是最好的习惯:
val route = tbl.`as`("route")
val srcPlace = Tables.PLACE.`as`("srcPlace")
val dstPlace = Tables.PLACE.`as`("dstPlace")
val records = dsl
.select(route.asterisk())
.select(srcPlace.asterisk())
.select(dstPlace.asterisk())
.from(route)
.join(srcPlace).on(route.SRC_ID.eq(srcPlace.ID))
.join(dstPlace).on(route.DST_ID.eq(dstPlace.ID))
.limit(pageable.pageSize)
.offset(pageable.offset)
.fetch {
val r = it.into(route).into(RouteEntity::class.java)
val sP = it.into(srcPlace).into(PlaceEntity::class.java)
val dP = it.into(dstPlace).into(PlateEntity::class.java)
r.srcPlace = sP
r.dstPlace = dP
r
}
如何做得更好?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法(从JOOQ 3.17和投影表表达为
selectfield
)的能力就是仅投影表本身,例如:在您的特殊情况下,您甚至可以通过使用 nofollow noreferrer
“
it
破坏性:The easiest way (starting from jOOQ 3.17 and the ability of projecting table expressions as
SelectField
) is to just project the tables themselves, e.g.:In your particular case, you can even simplify things further by using implicit joins
Or even, without the
it
destructuring: