Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.1
-
Fix Version/s: 1.2-M2
-
Component/s: None
-
Labels:None
-
Environment:Tested on both Windows XP and Mac OS X 10.5
Description
I have a controller which deletes a domain object. The domain object has a beforeDelete event. In that event I load another domain object and try to delete it but nothing happens. There is a beforeDelete event in the ProductLevel object but that's not called either.
This is my beforeDelete event:
def beforeDelete = {
def pl = ProductLevel.get(objectId)
log.debug "To delete: " + pl
if(pl) {
log.debug "Calling delete"
pl.delete()
}
}
I believe I see the same phenomenon. Here are the relevant pieces of a little sample project I wrote to smoke out the bug:
Domain classes:
=============
class Person {
String name;
static constraints = {
}
static hasMany = [
initiating: Relationship,
recipient: Relationship
];
static mappedBy = [
initiating: 'initiator',
recipient: 'recipient'
];
static mapping = { initiating cascade:'all, delete-orphan' recipient cascade:'all, delete-orphan' }
}
class Relationship {
String name;
Person initiator;
Person recipient;
static belongsTo = [initiator:Person, recipient:Person]
def beforeInsert = { initiator.addToInitiating(this); recipient.addToRecipient(this); }
def beforeDelete = { System.out.println("This is not happening"); // Never fires. initiator?.removeFromInitiating(this); recipient?.removeFromRecipient(this); }
static constraints = {
}
}
Failing integration test:
==================
import grails.test.*
class PersonTestTests extends GrailsUnitTestCase {
Person a;
Person b;
RelationshipType rt;
Relationship r;
protected void setUp() { super.setUp(); rt = new RelationshipType(name: "rt"); a = new Person(name: "a"); a.save(flush:true); b = new Person(name: "b"); b.save(flush:true); r = new Relationship(initiator: a, recipient: b, name: "relationship"); r.save(flush:true); }
protected void tearDown() { super.tearDown() // r.delete(flush:true); a.delete(flush:true); b.delete(flush:true); a= null; b= null; r= null; }
void testSomething() {
}
}