IceCream
IceCream copied to clipboard
hierarchy is not right on fetching
Models
@objcMembers
class Task: Object {
dynamic var id: String = UUID().uuidString
@objc dynamic var title: String? = nil
@objc dynamic var project: Project?
dynamic var isDeleted = false
override class func primaryKey() -> String? {
return "id"
}
}
@objcMembers
class Project: Object {
dynamic var id: String = UUID().uuidString
dynamic var title: String = ""
dynamic var startDate: Date = Date()
dynamic var isDeleted = false
override class func primaryKey() -> String? {
return "id"
}
}
Expected behavior
Look for CKReference
in model properties and fetch that object earlier than the model object itself.
If task's project is not nil:
- search for that object in local database and set project property.
- if not exists in local,first fetch project and then create task and set project property.
Is it possible to add hierarchy on fetching objects? Is fetching based on last modified date?
Actual behavior
I have 2 tasks saved in cloud both connected to ProjectA, project field in CloudKit Dashboard referenced as well and it's confirmed.
I have tested more than 10 times, randomly task1 get project right and task2 project is nil and vice versa. there's no custom implementation and I'm sure it happens because sometimes Project
objects fetched earlier than Task
objects and sometimes not.
better example: SyncEngine starts fetching objects without considering hierarchy:
- task2 fetched & there is no projects in local database, so
task2.project = nil
- projectA fetched.
- task1 fetched & there is the project needed, so
task1.project = projectA
Steps to reproduce the problem
Just add this 2 tasks and wait to be stored in iCloud with SyncEngine, now test them multiple times, by deleting app and try to fetching stored data from iCloud.
further thanks to all contributors.
Did you get any solution? I'm facing the same for one to many relationships.
I have same problem(