Hi all,


In my model I have Entities with to-many relationships that I choose not include as class properties. The problem is when I delete an eobject of such an entity the delete rules do not apply thus causing the delete operation to fail. I've overridden the delete method of my class for EObjects (wich extends ERXGenericRecord) to this :


    public void delete() {

        for (EORelationship relation : entity().relationships()) {
// to-many relationship that is not in class properties with
            // cascade as delete rule
            if (relation.isToMany()
&& relation._stringFromDeleteRule(relation.deleteRule()) .equals (EORelationship.DeleteRuleCascadeString) && ! entity().classPropertyNames().contains(relation.name())) {

EOQualifier qualifier = relation.qualifierWithSourceRow(this
                        .snapshot());
EOFetchSpecification fetchSpecification = new EOFetchSpecification( relation.destinationEntity().name(), qualifier, null);
                // fetching objects for the relationship
                NSArray<ERXGenericRecord> objects = editingContext()
.objectsWithFetchSpecification (fetchSpecification);

                // now delete them
                for (ERXGenericRecord eoGenericRecord : objects) {
                    eoGenericRecord.delete();
                }
            }
        }
        super.delete();
    }

This seems to work fine for me, but I was wondering if this is a good way of handling my problem?


Benoit Havret
[email protected]

ALGO DATA
+33 251 80 85 85

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to