Im using Exposed v0.57.0 and the DAO approach, and...
# exposed
i
Im using Exposed v0.57.0 and the DAO approach, and I have created two columns for storing the date and time when a record is created and modified according to the example in Auto-fill columns on entity change (with use of the
EntityHook
interceptor and the
Updated
action). However, the
changedEntity.writeValues
is always empty in the
BaseEntityClass
, even when there is a change to one or more properties of the Entity. Any hints on what Im doing wrong?
n
Not sure if you have solved this but I vaguely remember encountering a similar issue a long while ago. The current way I implement is this and it works very well:
Copy code
abstract class BaseEntity(id: EntityID<Int>, table: BaseTable) : IntEntity(id) {
    val createdAt by table.createdAt
    var updatedAt by table.updatedAt
    var isDeleted by table.isDeleted
}

abstract class BaseEntityClass<E : BaseEntity>(table: BaseTable) : IntEntityClass<E>(table) {
    init {
        EntityHook.subscribe { action ->
            if (action.changeType == EntityChangeType.Updated) {
                action.toEntity(this)?.updatedAt = Instant.now()
            }
        }
    }
}

open class BaseTable(name: String) : IntIdTable(name) {
    var createdAt = timestamp("created_at").defaultExpression(CurrentTimestamp)
    var updatedAt = timestamp("updated_at").defaultExpression(CurrentTimestamp)
    var isDeleted = bool("is_deleted").default(false)

    companion object : IntIdTable()
}
🙌 1
i
Thanks!