views:

300

answers:

1
+1  A: 

Sounds like you are setting something to nil somewhere and causing you to get nil back. I would walk through your save and fetch code in the debugger and look for objects being set to nil when you do not expect it.

update

Do you have any code anywhere that can be manipulating the relationships? Perhaps something in the -awakeFromFetch: that is causing the relationships to get corrupted?

If they are saving correctly the first time and then failing then that truly points at something in your code corrupting those relationships. Are you subclassing NSManagedObject for these objects? If so are you by chancing overriding the -init... method?

update

That last tick should definitely not be there. Check your fetch request, this might all boil down to a simple typo in a string somewhere...

Marcus S. Zarra
Thanks for all the help Marcus, it's much appreciated. I've added some more information to the question, but at the minute it feels like I just need to battle through the code to find what is being called during or after the save to cause the problem.
Ian Turner
It may not be occurring during the save. It might be something that is going on during the fetch. Based on your comments and notes I believe that is where you should be focusing.
Marcus S. Zarra
Thanks Marcus. Think I'm very slowly getting there. I've managed to get a fetch fail before a save so it looks like you were spot on. Still can't see why something would appear when you call [managedObjectContext registeredObjects] but fails when you try get it using a simple fetch request.
Ian Turner
It doesn't seem to be a simple typo. The request seems to work initially and then breaks after saving or after repeated requests. I've searched my project for the uptick and haven't found it. Any other idea what I might have done for it to appear?
Ian Turner