Does anyone know how to change the default "cascade" behavior in Grails 4.x?

Viewed 67
class ObjectA {

    ObjectB objectB

    static mapping = {
       objectB cascade: 'none'
    }
}

class ObjectB {
}

In the example above both ObjectA and ObjectB are "domain" classes in Grails. ObjectA has an association to ObjectB. In the mapping of ObjectA cascade is set to 'none' which disables cascading saves to objectB.

Is there anyway to make this the default cascade behavior for ALL domain classes without having to have a mapping defined for every association?

1 Answers

I haven't tried this by myself but you can try the following configurations -

create a file with the name runtime.groovy in grails-app/conf/ and put following content in that -

grails.gorm.default.mapping = {
    '*'(cascade: 'none')
}

Let me know if this works or not. I may also need to use this in future. :-)

Related