Consider the following simple entity model: Entity A has a to-one relationship with Entity B called b. Entity B has an inverse relation to one called a. None of these are required.
AB b < ----- > a
Suppose we have two devices (1) and (2) that start to fully synchronize. Each of them has one object of class A and one object of class B, and they are connected to each other. On device 1, we have objects A1 and B1, and on device B we have the same logical objects A1 and B1.
Now suppose that on each device simulated changes are made:
On device 1, we remove B1, insert B2, and match A1 to B2. then save the changes.
On device 2, we remove B1, insert B3, and match A1 to B3. Then save the changes.
Device 1 is now trying to import transaction logs from device 2. B3 will be inserted, and A1 will be associated with B3. So far so good, but now B2 remains with a ratio of zero. The relationship a is not optional, so a validation error occurs.
Something similar will happen on device 2, because there are two objects B and only one object A with which you need to associate. Thus, there should always be a validation error, since one of the B objects must have a relation set to nil.
Worse, any future changes always leave the stray object B hanging around, and therefore will refuse to check. In fact, the user cannot solve the problem on his own, dropping the relationship. He is constantly disturbed.
The question is, how can you address a validation error like this? All this happens before the NSPersistentStoreDidImportUbiquitousContentChangesNotification
notification is NSPersistentStoreDidImportUbiquitousContentChangesNotification
. This is not a validation error in the main NSManagedObjectContext
applications, it is a validation error that occurs during the initial import of transaction logs into persistent storage.
The only possibility I can think of is perhaps to try to delete the invalid B object in the user setter ( setA:
or in the KVC validation method ( validateA:error:
in class B itself, since they seem to work during import transaction log. But I'm not sure that such side effects are resolved, and when I try to do this, it seems that this leads to unpleasant log messages on this subject.
Does anyone know which is the right way to handle this?