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

To One relationship with mapped relationship name results in crash while trying to sync #118

Closed
GabrielHauber opened this issue Jun 17, 2021 · 1 comment

Comments

@GabrielHauber
Copy link

Steps to reproduce:

  1. Define a content model SomeModel in Contentful with a to-one relationship to another model SomeOtherModel. Let's call this relationship in Contentful toOneRelationship
  2. Define the core data model with the to-one relationship, but in the core data model, call the relationship justOne
  3. Define the core data NSManagedObject class as EntryPersistable, with the following field mapping:
class SomeOtherModel: NSManagedObject, EntryPersistable {}
class SomeModel: NSManagedObject, EntryPersistable {
    // this is called "toOneRelationship" in the Contentful model
    @NSManaged var justOne: SomeOtherModel?

    static func fieldMapping() -> [FieldName: String] {
        [
            "toOneRelationship": "justOne"
        ]
    }
}

During the sync operation, ContentfulPersistence will attempt to set the relationship on this managed object using the toOneRelationship name, rather than the justOne field name, resulting in a crash.

Only workaround seems to be to rename the relationship in the Contentful model definition.

@GabrielHauber
Copy link
Author

… and I found that it actually works.
The problem was a stale cache - I had been using the old property name in the managed object model, decided there was a better name, renamed it in Core Data, updated the mapping, etc. Also had deleted the persistent store and created from scratch. However, ContentfulPersistence had a cache on disk containing the old mapping. After I removed the app and reinstalled (which obviously removed the cache) then it started working.

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

No branches or pull requests

1 participant