我有2个班级的汽车和停车场。 他们有一米:n关系,因此一辆汽车有许多停车场,一辆汽车多。
I have a garage_has_car table in my database, where the relations are stored. I have configured set belongsTo on the car to Garage
static belongsTo = [ Garage ]
如果我清扫停车场和储蓄的汽车收集工作,则将车库中的相应条目删除。
但是,如果我清除了车上的垃圾收集并节省费用,那么车库中相应的条目——has车桌上没有删除!
我如何能够实现这一行为?
www.un.org/spanish/ecosoc 1 (关于关系的定义):
婚姻关系是:
cars column: deskriptor_id ,joinTable: garage_has_cars
Car
static belongsTo = [ Garage ]
garages column: car_id ,joinTable: garage_has_cars
我也曾在国际排雷中心问这个问题,有人回答:
(...) grails many to many relationships are always only cascade one direction. also many-to-many relationships in grails are horribly inefficient with how they get mapped in hibernate. don t use them. create a joinclass domain object CarGarage with 1 car and 1 garage. make cars and garages properties of your classes transients and add get and add methods to the car and garage classes which use your joinclass for maintaining the relationship. you also want to disable versioning in the join class here s some info can be found in this presentation http://burtbeckwith.com/blog/files/169/gorm%20grails%20meetup%20presentation.pdf and the notes of it are here: Grails: Many-to-Many without hasMany/belongsTo - instead using native 3NF - Searching full text
我之所以这样说,是因为它可以帮助问题与我一样的人。 一旦我有时间实施这些变化,我也将更新这个问题。