Skip navigation.
 
mlRe: Core Data Cascade delete rule sometimes doesn't
FROM : Adam Swift
DATE : Mon Feb 11 20:19:10 2008

On Feb 10, 2008, at 8:21 PM, Doug Knowles wrote:

> I have an "item" entity in a core data application with a to-many
> relationship to a second entity; the relationship's delete rule is 
> set to
> "cascade", and the inverse (to-one) relationship's delete rule is 
> set to
> nullify.
> I implemented a simple action in my application to delete a selected 
> item,
> which invokes a "delete" method on item to do some cleanup before 
> ultimately
> invoking deleteObject:self on the managed object context. 
> Everything works
> as expected; deleting the item causes the relationship's target 
> objects to
> be deleted.
>
> I have just implemented an AppleScript command to delete an item, 
> which
> invokes the same "delete" method on item.  However, when the 
> operation is
> completes, the destination objects are not deleted (although the 
> references
> in both directions are cleared).  This leaves my store in an invalid 
> state
> because the target objects are not deleted and have no value for the 
> inverse
> relationship back the item, which is not optional.
>
> I can't figure out any reason why this should behave differently in 
> the two
> different circumstances.  No exceptions are being thrown, and I've 
> stepped
> through the AppleScript deletion and it appears to complete normally.
>
> I have seen this problem in other contexts and coded around it (by 
> deleting
> the target objects explicitly) under the assumption that I was doing
> something wrong.  This is the first case I've encountered where the 
> same
> method works in one situation and fails in another.
>
> Any ideas?
>

Have you tried manually calling "processPendingChanges" after the 
delete?  Cascade deletes are not processed immediately:

http://developer.apple.com/releasenotes/Cocoa/CoreDataReleaseNotes/index.html

> TIA,
> Doug K;
>
> P.S. I've considered filing a bug report, but I can't isolate this 
> code, and
> I know the cascade rule works most of the time, so coding a simple 
> test case
> will in all likelihood not expose the apparent bug.
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>

Related mailsAuthorDate
mlCore Data Cascade delete rule sometimes doesn't Doug Knowles Feb 11, 05:21
mlRe: Core Data Cascade delete rule sometimes doesn't Adam Swift Feb 11, 20:19
mlRe: Core Data Cascade delete rule sometimes doesn't Doug Knowles Feb 11, 22:27