https://kotlinlang.org logo
p

Philipp Mayer

08/18/2020, 4:02 PM
Hey guys! I'm currently working with Exposed and its a breeze! However, I stumbled upon a thing that I don't quite understand yet. I have the following table:
Copy code
object Sensors : IntIdTable() {
    val roomId = reference("id", Rooms.id).nullable()
    val name = text("name")
}
And now I just want to select all rows and map them to my domain Object:
Copy code
class Sensor(
        val id: Int?,
        val roomId: Int?,
        val name: String
)

Sensors.selectAll().map {
      Sensor(it[id], it[roomId], it[name])
}
However, if I do it as shown, I get an alert saying that
it[id]
is of type string (while I expect an int). Ist htere a better way? Why is it like that, even though my table definition is different? Thanks in advance!
t

tapac

08/18/2020, 4:26 PM
You have to either provide explcit name for Seniors id column via IntIdTable
columnName
parameter or rename
reference("id", Rooms.id)
into
reference("roomId", Rooms.id)
.
p

Philipp Mayer

08/18/2020, 4:35 PM
That was a fast answer! So easy. Thanks a lot.
😄 1