small medium large xlarge

Back to: All Forums  Core Data
Generic-user-small
15 Aug 2009, 15:31
Jennifer Marden (3 posts)

First of all, thanks so much for the book, it’s really helped my understand this complex topic.

My question is about whether I should use nullify or cascade for a certain “to-many” relationship I have. I have a page object which can optionally contain one image object. The image object can be contained in 1 or more pages at a time. I know that the image -> page delete rule should be nullify, as I wouldn’t want the page to be deleted if its image is deleted. For the page -> image delete rule, I’m not sure whether to use nullify or cascade. What I want to happen is that the image should be deleted when the page is deleted iff no other page is referencing the image (i.e. the count on the image -> page relationship goes to zero). Will the cascade rule check the relationship count and only delete the image if the count is zero? Or should I set the image->page delete rule to nullify and keep track of the number of referencing pages myself, and do the delete of the image manually when appropriate?

Thanks so much!

Jennifer Marden

Generic-user-small
15 Aug 2009, 15:33
Jennifer Marden (3 posts)

Please ignore the cross outs in my original post - in using the “greater than” character to help represent a relationship, I seem to have told the discussion forum software to generate cross outs. Sorry!!

Jennifer Marden

Avatarsmall_pragsmall
25 Aug 2009, 16:28
Marcus S. Zarra (284 posts)

Personally I would override the @- (void)prepareForDeletion@ method and handle the logic there. That will let you check the image object manually, count the references and decide if it needs to be deleted.

Generic-user-small
25 Aug 2009, 20:40
Jennifer Marden (3 posts)

Thanks! That makes sense, I’ll give it a try!

Jennifer

You must be logged in to comment