Skip to content

Conversation

@codeconsole
Copy link
Contributor

@codeconsole codeconsole commented Jan 14, 2025

Useful if importing data. If set to false, AutoTimestamp will only set create and update fields if they are null during insertion events. Defaults to existing behavior which is true.

Setting

grails:
    gorm:
        events:
            insertOverwrite: false

allows:

class User {
    Date dateCreated
    Date lastUpdated
}

def user = new User()
user.dateCreated = new Date() - 1
user.save(flush:true)
assert user.lastUpdated != null
assert user.dateCreated != user.lastUpdated

Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, I thought it didn't set the created if it was already set. I'm ok with this change, but this needs test coverage. We shouldn't be changing this without associated tests.

@codeconsole
Copy link
Contributor Author

codeconsole commented Jan 15, 2025

@jdaugherty yeah, it's normal behavior is unexpected and that is why I introduced this in the first place.

I added test coverage.

Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add documentation for these features in gorm.grails.org. Can you create a ticket and do this before we go live with Grails 7?

@codeconsole codeconsole merged commit 7e43a28 into apache:9.0.x Jan 15, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants