【发布时间】:2019-08-23 22:44:03
【问题描述】:
我可以在 Kotlin 公开库上找到的所有材料都假定该表具有一个主要的标识列,因此在大多数示例中显示的实体都继承了 IntEntity 抽象类。例如:
class UserLocation(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<UserLocation>(UserLocations)
var userId by UserLocations.userId
var user by User referencedOn UserLocations.user
var recordedAt by UserLocations.recordedAt
var insertedAt by UserLocations.insertedAt
var point by UserLocations.point
并且对应这个表定义:
object UserLocations : IntIdTable("user_locations") {
val userId = integer("user_id")
val user = reference("user_id", Users)
val recordedAt = datetime("recorded_at").nullable()
val insertedAt = datetime("inserted_at")
val point = point("point")
}
问题是,我的表实际上没有标识列。我知道没有主键的表的所有负面影响,但不幸的是我只有对该表的读取权限。我无法获得对该表的写入权限来添加主键。
在公开库的 wiki 中,它提到对象表定义可以继承 Table 而不是 IntIdTable,但这需要实体继承一些不同的东西,我无法完全找到实体应该继承而不是IntEntity。
我的问题:当表没有 id 列时,我的实体应该继承什么(而不是 IntEntity)。
【问题讨论】:
-
你能显示你想要使用的当前表定义吗?
标签: sql postgresql kotlin primary-key kotlin-exposed