With the impending death of Parse, I'm re-writing an app using CloudKit. Suppose I'm making a recipe scheduling app. I want a given schedule to contain an ordered list of recipes, and recipes can be in multiple schedules. So I have:
Assume I have the Schedule object, and I want to get all of its ScheduleItems AND their associated Recipes in one single query. In Parse, I could set up this query:
PFQuery *query = [PFQuery queryWithClassName:@"Schedule"];
[query includeKey:@"scheduleItems.recipe"];
And that query would fetch all the scheduleItems along with all their recipes, allowing me to avoid having to perform multiple network requests.
Is there a way to do this in CloudKit? I see that I can use a CKFetchRecordsOperation
to fetch multiple records at once given their recordIDs, but I wouldn't know the record IDs of the recipes until I had already fetched the scheduleItems, thus still necessitating a second network request.
CloudKit is not a relational database. It's a key-value store. There is no functionality to query multiple recordType's in one query. There is also no functionality for aggregation queries. In your case since it's a one to one relationship you could limit it to 2 queries by adding a CKReference in your Recipe to the Schedule. So then if you have a schedule, you could do one query to get all related ScheduleItem's and an other query to get all related Recipe's
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With