Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 0.6
-
Component/s: None
-
Labels:None
-
Environment:Revision 5339
Description
When I have a domain class that uses 'static belongsTo = [ prop: relClass ]', deleting an instance of that class causes the related instance to be deleted on PostgreSQL. If any other instances link to the same related instance, that delete will fail, throwing an exception.
Take the following domain classes for example:
class Role {
String name
}
class UserRoleRel {
String username
static belongsTo = [ role: Role ]
}
Deleting an instance of UserRoleRel will also delete the associated Role instance. The problem appears to stem from GrailsDomainBinder - in particular the bindProperty() method:
public static void bindProperty(...) { ... // in a one-to-one we check if it is un-directional and the other side is an owning side and then cascade // otherwise if is the ownside we cascade all else if(grailsProperty.isOneToOne()) { GrailsDomainClass domainClass = grailsProperty.getDomainClass(); if(!grailsProperty.isBidirectional() && domainClass.isOwningClass(grailsProperty.getType())) { // THIS IS CALLED! prop.setCascade(CASCADE_ALL); } else if(grailsProperty.isOwningSide()) { prop.setCascade(CASCADE_ALL); } } ... }
The line after "// THIS IS CALLED!" is invoked for the 'role' property, setting up a cascading delete, even though it is not the owning side of the relationship.
I have attached a simple example that exhibits the problem.
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits