[CORE DATA] Core Data and NSArrayController behavior when deleting a NSManagedObject
[CORE DATA] Core Data and NSArrayController behavior when deleting a NSManagedObject
- Subject: [CORE DATA] Core Data and NSArrayController behavior when deleting a NSManagedObject
- From: Aurélien Hugelé <email@hidden>
- Date: Tue, 13 Dec 2005 19:22:03 +0100
Hi list !
i have a problem with core data and array controller (used to display
a tableview) when deleting a NSManagedObject.
The array controller is populated with NSManagedObject objects, of
entity "Note".
The array controller contentSet is bound to another array controller
using keypath : @"selection.notes". Both array controller are bound
to the same managedObjectContext.
notes are retrieved from a (bidirectional) relationship from another
NSManagedObject (which is the "selection", in the key path above).
when removing an object "note" using NSArrayController -(IBAction)
remove: method, the note object is not *deleted* from the MOC or the
store, but removed from the array controller and by consequence from
the tableview. I want *deletion*... not removal...
when removing an object "note" using NSManagedObjectContext -(void)
deleteObject: method, the note object is correctly deleted from the
MOC (validateForDelete: and didTurnIntoFault are called), but this
creates the now famous "Core Data could not fulfill a fault" error
when the tableview is reloaded, when (i suppose) the deleted note
object is accessed!
i consider this a bug or at least a bad behaviour, because, to me,
when an object is deleted from the MOC/store, the bound array
controller(s) should be informed of the deletion, and they should
rearrange them self !?
after all, if i understand it correctly, the relation ships of the
"selection" object is modified when a note is deleted (the
(bidirectional) relation ship is nullified) so the array controller
should be informed because @"selection.notes" did change...
Now, i suppose there is a logic behind this and this strange
behaviour may be the right one for reasons i do not suspect... so
what is the recommanded way to refresh an array controller when one
object it contents is deleted from the MOC ?
Listening to NSManagedObjectContextObjectsDidChangeNotification ?? i
think it is not the best way, because I seem to be litterally
*bombarded* by this notification... and checking if deleted objects
(NSDeletedObjectsKey) are in the array controller, then removing
them, each time i receive this notification, may cause performance
problems.... and seems poor design :)
any advice ?
i have a *very small* project to demonstrate the problem, i can
upload it to anyone interested...
thanks for your help !
_______________________________________________
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