Core Data Object doesn't seem to be deleted

  • i've got an entity that is a tree that has parent-child relationships. i.e.:
    EntityA <-->> EntityA
    i.e. EntityA has a to-many relationship, subEntities, with an inverse
    of parentEntity. both relationships are optional and have a NULLIFY
    delete rule.

    in some cases, i will create a "temporary" instance of this entity via:

    +(EntityA*) temporaryEntityInManagedObjectContext:
    (NSManagedObjectContext*) moc parent: (EntityA*) inParent {
    BOOL undoWasEnabled = [[moc undoManager] isUndoRegistrationEnabled];
    if (undoWasEnabled) {
    [moc processPendingChanges];
    [[moc undoManager] disableUndoRegistration];
    }
    EntityA* result = [NSEntityDescription
    insertNewObjectForEntityForName: @"EntityA" inManagedObjectContext:
    moc];
    [result setParentEntity: inParent];
    if (undoWasEnabled) {
    [moc processPendingChanges];
    [[moc undoManager] enableUndoRegistration];
    }
    return result;
    }

    later on i will delete this temp instance via:

    +(void) deleteTemporaryEntity: (Entity*) inTemp managedObjectContext:
    (NSManagedObjectContext*) moc {
    BOOL undoWasEnabled = [[moc undoManager] isUndoRegistrationEnabled];
    if (undoWasEnabled) {
    [moc processPendingChanges];
    [[moc undoManager] disableUndoRegistration];
    }

    [moc deleteObject: inTemp];
    if (undoWasEnabled) {
    [moc processPendingChanges];
    [[moc undoManager] enableUndoRegistration];
    }
    }

    however, if i later access the subEntities of the above parent, the
    temp entity is still showing up. fwiw, my accessor is:

    - (NSSet*) subEntities {
        NSSet* tmpValue;
        [self willAccessValueForKey: @"subEntities"];
        tmpValue = [self primitiveValueForKey: @"subEntities"];
        [self didAccessValueForKey: @"subEntities"];
        return tmpValue;
        }

    i've worked around this for the time being by filtering the result of
    subEntities based on an mandatory attribute that must be non-zero.

    however, why is the deleted object still showing up in my object
    graph? also, although my app currently in non-threaded and use only
    one MOC for the document throughout, would i perhaps be better served
    by creating a different MOC for my temporary instances?

    thanx,
    ken
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today