You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Mike Kienenberger <mk...@gmail.com> on 2006/07/27 22:13:24 UTC

Delete Rules: Cascade with Deny on reverse relationship

If I have object Department, and a to-many relationship to Employees
marked Cascade, and then Employee has a to-manys relationship to
Departments marked Deny, will it work if I try to delete a department?

What I want to do is deny the deletion when an Employee is a member of
multiple departments, but not when an Employee is a member only of the
department being deleted.

(This isn't really a case of Department and Employee, but it seems
like a good analogy).

Or to put it another way, does the Deny still happen if the only
reverse-relationship value is the cascading original object to be
deleted?

Re: Delete Rules: Cascade with Deny on reverse relationship

Posted by Andrus Adamchik <an...@objectstyle.org>.
Doesn't look like DataContextDeleteAction is smart about it:

	    if (relatedObjects.size() == 0) {
                 continue;
             }

             // process DENY rule first...
             if (relationship.getDeleteRule() == DeleteRule.DENY) {
                 object.setPersistenceState(oldState);

                 String message = relatedObjects.size() == 1
                         ? "1 related object"
                         : relatedObjects.size() + " related objects";
                 throw new DeleteDenyException(object,  
relationship.getName(), message);
             }

To handle cascade/deny combination we may need to change this code to  
check that at least one object in 'relatedObjects' collection is  
itself not deleted.

Andrus



On Jul 27, 2006, at 4:13 PM, Mike Kienenberger wrote:
> If I have object Department, and a to-many relationship to Employees
> marked Cascade, and then Employee has a to-manys relationship to
> Departments marked Deny, will it work if I try to delete a department?
>
> What I want to do is deny the deletion when an Employee is a member of
> multiple departments, but not when an Employee is a member only of the
> department being deleted.
>
> (This isn't really a case of Department and Employee, but it seems
> like a good analogy).
>
> Or to put it another way, does the Deny still happen if the only
> reverse-relationship value is the cascading original object to be
> deleted?
>