Start a new topic

How to set relational data in BL?

I have a collection "A", which has a property "b" which points to an object in collection "B". And every time I create a new "B", I want to update a specific "A"'s "b" property to include it. Not just the _id, but a "relational Data" object, so that when I pull an "A" from the server, I get the most recent "B" associated with it. So I've added an onPostSave() BL script for "B", after I save the "B", I do other things with it; I can easily get the right "A" instance on my BL script, because I had the _id for it. But when I try to set the "A"'s "b" property to relate to the "B" in findAndModify() ...{'b':body}... I only get the properties for the "B" instead of the full "B" object - at least it appears this way in the console. using tells me the "body" is an [Object object], yet following the documentation for the iOS SDK for relational data I only get a dictionary of properties for "b", instead of an actual "B". I tried retrieving the "B" instance in its onPostSave with a findOne(), which I thought would be easy if I had the _id, but "body" doesn't have an "_id" property. the request's entityID is undefined (probably because I created a new object). So question is: from onPostSave for collection "B", how do I properly set relational data on a property "b" in collection "A" assuming I have the correct object from the "A".
1 Comment

It turns out I was getting the body from the request, not the response. the response.body does indeed have a _id set. The answer is more complex, as a proper object must be created {'_type':'KinveyRef','_id':"......", '_collection':'....'}
Login or Signup to post a comment