digitalbreed
digitalbreed

Reputation: 4070

Grails / Gorm: Disable implicit association between two domain classes

I am using Grails 2.4.4 and have two domain classes,

class User {
    Image image
}
class Image {
    User user
}

I have a user loaded and create a new image with

def image = new Image(user: user)
image.save()

GORM now automagically updates the user's image to point to the newly saved Image.

Is there any way to disable this behavior? The nice folks in #grails advised to use static mapping = { user cascade: 'none' } but this didn't help.

(Here is a very similar question but I would like to avoid modelling a relationship with belongsTo/hasOne and just get rid of this magic.)

Upvotes: 1

Views: 85

Answers (1)

digitalbreed
digitalbreed

Reputation: 4070

Thanks to Ian Roberts for the link to the mappedBy documentation. I wasn't aware of the "none" magic.

This resolved the issue for me:

class Image {
    User user
    static mappedBy = [ user: "none" ] // *** added ***
}

Upvotes: 2

Related Questions