Re: EOModel - Cascading Delete Rule for relationship wich is not a class property
Re: EOModel - Cascading Delete Rule for relationship wich is not a class property
- Subject: Re: EOModel - Cascading Delete Rule for relationship wich is not a class property
- From: Denis Frolov <email@hidden>
- Date: Tue, 13 Oct 2009 00:19:01 +0400
Hi,
I think willDelete() is a better place to do that...
On Mon, Oct 12, 2009 at 8:03 PM, Benoit Havret <email@hidden> wrote:
>
> 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@hidden
> ALGO DATA
> +33 251 80 85 85
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden