Core Data Object doesn't seem to be deleted
Core Data Object doesn't seem to be deleted
- Subject: Core Data Object doesn't seem to be deleted
- From: Ken Victor <email@hidden>
- Date: Mon, 16 Oct 2006 13:39:46 -0700
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden