https://kotlinlang.org logo
j

James Myers

12/21/2021, 3:01 PM
Hi folks. I was following the recommendation for server side timestamps by using the following:
Copy code
val updatedAt = datetime("updated_at").defaultExpression(CurrentDateTime())
I was looking at the following chunk for using the
EntityHook
and it wasn’t clear how to leverage the
CurrentDateTime
here as well:
Copy code
EntityHook.subscribe { action ->
            if (action.changeType == EntityChangeType.Updated) {
                action.toEntity(this)?.updatedAt = LocalDateTime.now(Clock.systemUTC())
            }
        }
I’ve tried looking through the code/docs but wasn’t able to find an example of how to do this properly. Is there something obvious that I’m missing here, or do these two not work very well together. Any help would be appreciated. Thanks!
d

dave08

12/21/2021, 3:59 PM
I think the EntityHook only applies to DAO api not the DSL...
If you want it for the DSL you'll probably need to implement your own insert or update function...
j

James Myers

12/22/2021, 3:27 PM
Makes sense. Darn, was hoping to be able to leverage the same logic. Thanks for the help.
27 Views