Ron S
04/27/2022, 8:45 AMclass UserEntity(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<UserEntity>(UserTable)
var username by UserTable.username
}
class TestEntity(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<TestEntity>(TestTable)
var author by UserEntity referencedOn TestTable.autor
// var author by TestTable.author // not this way
}
transaction {
TestEntity.all().first().author // triggers fetch of entire entity
TestEntity.all().first().readValues[TestTable.author] // returns the desired id but is a little awkward
}
I want to benefit from the dao api by fetching entire related entites (like author here).
However, there are some use cases when the id of the referenced entity is sufficient and I don't want to cause another database query to fetch the other unneeded columns.
The only - but awkward - way I found to achieve this was by using "readValues". Is there any better solution that I have overlooked?hfhbd
04/27/2022, 12:36 PMvar authorID by TestTable.author // or better val
? This works if authorID
is a FK.Ron S
04/27/2022, 1:08 PMhfhbd
04/27/2022, 1:08 PMRon S
04/27/2022, 1:10 PMhfhbd
04/27/2022, 1:12 PMclass TestEntity(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<TestEntity>(TestTable)
var author by UserEntity referencedOn TestTable.autor
var authorID by TestTable.author
}
Ron S
04/27/2022, 1:14 PMhfhbd
04/27/2022, 1:26 PMRon S
04/27/2022, 1:27 PM