Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync not removing invalid relationships? #122

Open
GabrielHauber opened this issue Oct 12, 2021 · 1 comment
Open

Sync not removing invalid relationships? #122

GabrielHauber opened this issue Oct 12, 2021 · 1 comment

Comments

@GabrielHauber
Copy link

This is the problem I'm having, and I think it's on the Contentful sync side…

The problem is this:

  1. Content synced where model A has relationship to model B
  2. Later, content is updated, removing the relationship between A & B. Both A & B content still exist though, just the relationship is removed
  3. Next sync, the relationship still exists in the synced data. I can't see anything in the code that would remove this relationship?
@GabrielHauber
Copy link
Author

Ok it turns out to have been a CoreData setup issue. The persistence SDK was doing the right thing in setting the new relationships, and even examining them before / after they were right, but the problem was in merging from background context to the view context.

i.e. Sync was performed on a background context using the default merge policy to the view context. This meant that the changes were merged, not overwriting, leaving both old & new relationships on a to-many entity relationship.

The fix was explicitly setting persistentContainer.viewContext.mergePolicy = NSMergePolicy.overwrite before performing the sync in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant