core data - Deletions in a many-to-many structure -
i want check quickly. have 2 entities in data model: catalog, , product. have many-to-many relationship each other, , both required (a catalog must have @ least 1 product, , products must each belong @ least 1 catalog). if delete product, deletion should nullify, of course.
but should deletion policy catalog? if catalog deleted, not of products exclusively belong it. product may belong more 1 catalog. shouldn't use cascade. however, nullify sufficient? if end dangling products don't belong catalog? core data have built in resolve issue many-to-many schemas? need modify schema?
nullify sufficient, , many-to-many sounds right. specific constraint want (deleting orphans) not directly enforceable core data, though, little cleanup yourself.
specifically, implement willsave
in entity classes, , have each entity test: not deleted; and, have no associated (products/catalogs)? if so, delete myself. (the not-deleted test important avoid infinite loop of willsave
s.)
this postpones deletion of orphaned catalogs or products until save time. not problem.
Comments
Post a Comment