foreign keys - Grails reverse cascade delete without hasMany or belongsTo -
i have 2 domain-classes.
class usersaddthese { string somedata }
and
class theseareconstantlygenerated { usersaddthese theproblem }
is there way delete usersaddthese
, automatically delete theseareconstantlygenerated
or should add in logic findallbytheproblem
, iterate , delete. (i prefer if done automatically can add new generated classes refer usersaddthese
, not change delete controller.)
alternatively, there way tell gorm, "if else depends on deleting cause error util.jdbcexceptionreporter - cannot delete or update parent row: foreign key constraint fails
, delete - recursively."
well, seems whole point of referential integrity not you're trying in 2nd part of question. however, can add closure usersaddthese domain class:
def beforedelete () { theseareconstantlygenerated.withnewsession { theseareconstantlygenerated.findallbytheproblem(this).each {theseareconstantlygenerated thing -> thing.delete() } } }
that should trick.
Comments
Post a Comment