this has been bugging me,
lets say i have two model, category and product
class Category {
static hasMany = [products : Product]
String name
}
..
class Product {
String name
}
now, i want to delete product, which happens to exist in many category. i came up with these lines in my product beforeDelete methods
def beforeDelete = {
Category.list()?.each{
it.removeFromProducts(this)
}
}
now this may works, but the way i see it, thats a lots of query for one simple task. i know i can get the same result just with a single line of sql string ("delete from category_product where product_id = ?"). but im just curious, is there more sophisticated way to achieve this in grails? (besides executing the sql string)