Ryan
Ryan

Reputation: 672

Deleted Object with Relationship is Re-Inserted by AFIncremntalStore

In my data model, I have Users and Notifications, where one User can have many Notifications. In Notifications, the delete rule on the user relationship is set to Nullify.

When I delete a record, I can see in controllerWillChangeContent, that it actually performs the delete, but then immediately performs an insert of the same record. And it seems to be stemming from the relationship.

In executeSaveChangesRequest, if I log the change request, I get:

<NSSaveChangesRequest: 0xff441e0> { inserts (), updates ((
"0xa95e9d0 <x-coredata://76F3..F8CF/User/p__af_1>"
)), deletes ((
"0xa983880 <x-coredata://76F34AF...BAF8CF/Notification/p__af_228>"
)) locks () }

So that looks good I think. It's deleting the Notification, and updating the User to say it no longer has that Notification.

After some digging, I'm finding that the unwanted insert is occurring in AFIncrementalStore's -newValueForRelationship. So for some reason, that deleted object is coming back through via the User's relationship.

How can I make sure the deleted object stays deleted and newValueForRelationship doesn't attempt to re-insert it?

Upvotes: 3

Views: 149

Answers (1)

Ryan
Ryan

Reputation: 672

Well, it's as simple as setting shouldFetchRemoteValuesForRelationship to return false. Can't claim I understand why, and this might come back to bite me, but for now, it solves this issue.

Upvotes: 1

Related Questions