• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data - "Items cannot be deleted from X"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data - "Items cannot be deleted from X"


  • Subject: Re: Core Data - "Items cannot be deleted from X"
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 20 Aug 2008 21:39:45 -0700

On Aug 20, 2008, at 20:21, Nick Zitzmann wrote:

I have two Core Data entities. Entity X has a to-many relationship with entity Y. On entity X, the relationship may refer to zero or many instances of entity Y, and deleting an instance of entity X is supposed to cascade-delete instances of entity Y. On entity Y, the inverse-relationship back to X is mandatory, and deleting an instance of entity Y is supposed to nullify the relationship to entity X.

But when I try to delete a saved record belonging to entity Y, the - validateForDelete: method always says NO, and returns error 1600, "Items cannot be deleted from (name of inverse-relationship pointing to X)." Why doesn't this work? It should be delete-able because Core Data is supposed to nullify the relationship to the entity X record, which is not being deleted, and furthermore instances of entity X do not need to have any relationships with instances of entity Y.

Are you calling validateForDelete manually? If so, are you calling it before or after deleting the Y object?


The error seems technically correct, given how literal Core Data is. Y's Nullify setting for its to-X relationship means that Y, when deleted, is going to get removed from X's to-Y relationship, and that means that Y's to-X relationship will incidentally get set to nil. But you've specified that Y's to-X relationship is non-optional, so nil is not valid.

I think you have several choices:

-- Don't validate the deletion. The deleted Y object will be invalid, but I doubt save:error: will complain.

-- Make Y's to-X relationship optional. After all, being non-optional doesn't mean that it can't be nil, just that the object is invalid if it is nil. You can add custom validation for Y's to-X property, or for validateForInsert and validateForUpdate, if you really need to check.

-- Set Y's to-X relationship to No Action instead of Nullify.

I suspect that the last option might be your easiest way out.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >Core Data - "Items cannot be deleted from X" (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Model Object Validation
  • Next by Date: Re: Best Way to Handle Properties?
  • Previous by thread: Core Data - "Items cannot be deleted from X"
  • Next by thread: Model Object Validation
  • Index(es):
    • Date
    • Thread