Start a new topic

Relational Data on iOS - I give up

Re: relational data fetching on iOS.

I have 2 ObjC classes. "A" and "B", both explicitly conform to KCSPersistable. They map to "A" and "B" collections on my backend, which exist and are populated. A has an @property for a "B". A's -hostToKinveyPropertyMapping has an entry for the "b" field (the local name and backend names are identical). It also has a +kinveyPropertyToCollectionMapping, which has the property name to collection name. I can save instances of A with a pointer to a live B and it works fine; I see what appear to be correct {'_type':'KinveyRef','_id':'...','_collection':'B'} on the backend: the collection names are correct and the _id's match the correct objects. Both the A and B instances were created by the user doing the fetching, and I haven't modified any ACL's yet. But when I fetch instances of A (from a KCSLinkedAppdataStore) I get NSDictionary's (__NSDictionaryM) instead of an instance of B. My whole point in doing this was that I could pull other properties of the B without doing a subsequent query. What ingredient am I missing for making simple 1-1 relational data work? am I missing an option when creating the store? I'm using KCSStoreKeyCollectionName:"A" and KCSStoreKeyCollectionTemplateClass:[A class]. The documentation tells me I don't need +referenceKinveyPropertiesOfObjectsToSave since I'm doing all of them, and save appears to work anyway. Documentation tells me I don't need +kinveyObjectBuilderOptions since these are not arrays (that's the next step once this one works), and implementing it didn't change the results. I'm building for iOS 8, (iPhone 6). The directory says I'm using KinveyKit 1.28.0, while it's Info.plist says I'm using KCSLibraryVersion : 1.5-SANDBOX.

Hello there Ben,

We have a few questions to better help us understand the issues that you're running into here.

1. If you're able to, would you be able to send a larger sample of your code to so we could make sure that your relationships are set up right?

2. Have you taken a look at the debugging guide at as that might help you have a better understanding of what's causing the issues that you're seeing.

3. Have you tried implementing kinveyObjectBuilderOptions? It's not essential that you do, but it might be of some use to you. ( )

4. Can you ensure that there's no recursive reference between types A & B are there?

Please let me know if you're able to solve the problem, and if not where we are after you take a look at the above.

The answer is that when I switched my code from searching on one parameter to another I inadvertently removed the code which created the query object. So my query object was nil. I guess I've been working in Swift too long to check for these bugs. It is interesting to note that a nil query will actually return objects, but won't have any relational data links resolved.

I'm taking it that you've figured it out and gotten it resolved then?

Well, now I have other problems. But a save followed by a fetch works for me now. The object that comes back from the save doesn't have relational data, and I'm getting a crash. Haven't had time to investigate.
Ok. Got it all resolved - except for the initial creating save having a dictionary instead of the relational data objects which were set just before the save. But I worked around that by refetching after the save happens. Which would be a minimal extra fetch.

Is there anywhere some sample working project with relational data that I can download and start with?

I tried to take a sample code from guides "Data Store" page and copy it to my solution.

The only changed I made are:

- changed the invitations property on Event to be (nonatomic, retain)

- allocated the NSMutableSet for invitations

- created an invitation and added it to event instance with addObject

After these changes I can't save the event due to the error 400 "The request body is either missing or incomplete".

Good morning Art,

Could you please provide me with a snippit of your code so we can take a look at it for you?


Hello Damien,

I solved it by replacing of KCSAppdataStore with KCSLinkedAppdataStore.

The guide is talking about this change by-the-way and it wasn't so obvious for me that I need to use an other storage provider...

But by the opportunity we are talking about, might I ask you an other question, please?

I've implemented the sample from the guide and mentioned the strange thing: despite of the hierarchy I've implemented, save of the Event object doesn't save the changed on the Invitations linked to the event. Is it correct behavior or I missed some thing?

The scenario I used is as following:

- created an invitation object and saved it with automatic id

- created an event object and added previously created invitation

- changed the status of the invitation 

- saved the event

As a result event was saved with reference to the invitation but invitation status wasn't changed.


I'm glad that you figured it out.  I'll note this as a deficiency in our guide for when we do an update to it in the future.


That's great )!
Any comments regarding to my question?

Art:  With regards to your question, its hard to say definitively without seeing any of your code, but we believe that the item would be saved if you used the referenceKinveyPropertiesOfObjectsToSave method, which is outlined in the guide at

Did you use that method?  If so can you share your code?


Regarding to your question: yes, I used this method with no changes in a result.

I've mailed you all sources of the project to the mail stated in the second post of the thread.

Thank you ahead for your help!

Login or Signup to post a comment