Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to force Grails/Gorm to not include a column in an insert?

For instance, suppose I wanted to let that column be set to whatever the database defaults it to, without redefining that default in the domain class?

I can't find much through Google. There are hints that if I were working with Hibernate directly, I could set that particular column/property to private, and this might accomplish what I seek.

I can of course leave that column undefined, and GORM ignores it. But I need the values out of it whenever the Grails app does a select.

like image 412
John O Avatar asked Oct 06 '22 14:10

John O


1 Answers

You can use the GORM property insertable as in doc or can read the value with a beforeInsert event:

class Book {
    String title
    String isbn

    static mapping = {
        isbn nullable: false
    }

    def beforeInsert {
        title = queryFromDatabase...
    }
}
like image 155
Nickmancol Avatar answered Oct 10 '22 02:10

Nickmancol