I am working with grails application with mongodb in the backend. I have two domain classes:
class User {
String login
String password
static hasMany = [
addWebsites: Website
]
static mapping = { addWebsites cascade:'all-delete-orphan' }
}
and other domain class as:
class Website{
String website
User user
static belongsTo = [user: User]
static constraints = {
website( url:true, unique: ['user'])
}
}
I tried deleting a user directly from mongodb and expected the realted websites to be deleted as well, but it didn't. I was wondering if I directly delete a user from the mongodb database, should it also delete the related websites or this cascade delete works only when we delete users via grails app?
Cascading as you have here only works within Grails and GORM via your Domain classes. It does not implement any database level triggers or constraints.