Maintaining integrity of Core Data Entities with many incoming one-to-many relationships
        Posted  
        
            by Henry Cooke
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Henry Cooke
        
        
        
        Published on 2010-06-04T02:20:09Z
        Indexed on 
            2010/06/04
            6:49 UTC
        
        
        Read the original article
        Hit count: 418
        
Hi all. I have a Core Data store which contains a number of MediaItem entities that describe, well, media items. I also have NewsItems, which have one-to-many relationships to a number of MediaItems. So far so good.
However, I also have PlayerItems and GalleryItems which also have one-to-many relationships to MediaItems. So MediaItems are shared across entities.
Given that many entities may have one-to-many relationships, how can I set up reciprocal relationships from a MediaItem to all (1 or more) of the entities which have relationships to it and, furthermore, how can I implement rules to delete MediaItems when the number of those reciprocal relationships drops to 0?
© Stack Overflow or respective owner