0

I'm currently implementing persistentStoreEnsemble:globalIdentifiersForManagedObjects: delegate and have a difficulty to decide about what global identifier to provide.

My Core Data model has two entities: book and image.

For book objects, there is no issue, as I should probably return a UUID, which should be stored in a dedicated property of the book.

However, I'm not sure about the global identifier for an image. Note that the image and book entities have one-to-one relationship in the data model, with a 'cascade' delete rule, which means that once a book is deleted, the linked image is deleted as well. So an image cannot exist in the database without being linked to a book.

Based on the above description, I was wondering if should I return NSNull, UUID, or a hash code (calculated at runtime from the image data) as the global identifier for a given image object?

Thanks for any suggestion.

Joshua
  • 1,974
  • 2
  • 23
  • 39

1 Answers1

1

Just use a UUID, I would say. I guess the image is stored as external data on the entity, right? If that is the case, Ensembles will sync it up, and will automatically use a hash to ensure it is not uploaded twice if the image happens to be the same. So for your entity, just use a UUID like you would for the book entity.

Drew McCormack
  • 3,490
  • 1
  • 19
  • 23
  • Your solution sounds correct, and will surely work with Ensembles. However, it will require me to add a persistent 'UUID' attribute for the Image entity, right? Instead of that, I came up with a solution where I don't add any attribute to the Image entity. I did that by using the UUID of the related book (there is one-to-one relationship between image and book) and appending a predefined string. So if a book returns "" from its UUID persisted attribute, as the global identifier, then the associated image will return something like "IMAGE: ". What do you think? – Joshua Mar 07 '16 at 20:03