Closed m1entus closed 8 years ago
Thanks @m1entus — is there any chance you can write a test to verify this problem (and fix), so that it doesn't resurface again?
Sure i will do that
My issue is that from parent contact object is not obtained permamentID.
I understand, and the test you've written makes that a bit clearer.
Why you are obtainingPermanentIDsBeforeSaving?
In the circumstance of the method you've updated (-[NSManagedObject MR_inContext:]
), I believe (it has been a while) temporary NSManagedObjectID
s do not resolve between contexts.
Given the purpose of MR_inContext:
(to retrieve a managed object from another context), it seemed wise to obtain the permanent IDs before attempting the lookup.
Could you expose
MR_obtainPermanentIDsBeforeSaving
?
Yeah, I can — but I'm not sure what it gives you that you can't build yourself using -[NSManagedObjectContext obtainPermanentIDsForObjects:error]
. What are you intending to use it for?
Current code is fine that's why i closed my PR, i had some issues with my code and temporaryIDs between contexts.
Yeah, I can — but I'm not sure what it gives you that you can't build yourself using -[NSManagedObjectContext obtainPermanentIDsForObjects:error]. What are you intending to use it for?
Same issue as here: https://github.com/magicalpanda/MagicalRecord/issues/1084 . I wanted to make main queue context with parent context. Instead of this i had to make:
+ (instancetype)re_newMainQueueContext { NSManagedObjectContext *context = [NSManagedObjectContext MR_newMainQueueContext]; context.parentContext = [NSManagedObjectContext MR_defaultContext]; [context re_obtainPermanentIDsBeforeSaving]; return context; }
There can be situation than permamentID was already obtained but context wasn't saved to persistent store so NSManagedObject will have still temporaryID.
MR_inContext will return nil instead of NSManagedObject if he was already obtained .