Hi,
I have the following scenario which need your help please
Using the console we can update link to related items in other tables , but as far I as know the same thing can’t be done using the client API…
Take this scenario for example :
If I have two tables “peopleNames” and “peopleContacts” and I have “Contact” Field to store 1-1 reference to “peopleContacts” in “peopleNames” Table …. now today If I need to link an item from “PeopleContacts” then first I have to query “PeopleContacts” for the object and then update the Contact” Field in “peopleNames” with it …this is fine but what if I already have the objectId of the record in “peopleContacts” can I just link it without updating or saving in “peopleContacts” ?
I couldn’t see anyway where I just link that “Contact” object without Querying “peopleContacts” records for that ObjectId and without the need to save or update the record in “peopleContacts” table …
Now if there is no way but to run that query first I have two issues with that :
1- It’s additional delay as I have to query for the whole Record before being able to update the “peopleNames” record when all I need is just to link that Object by objectId
2-There could be some updates on that same peopleContacts” record after I queried the table but before I actually update the “peopleNames” with the Related Contact Object … This means with my save or update API call it will actually update all those fields for the Contact record in the “peopleContacts” table … which mean overwriting some recent changes here also .
Because of the above issues, I thought there could be a way to just link a related object if we know the ObjectId …something similar to what we do in console today
am I missing anything here ?
Hello.
When you “just” link one object to another you do change that object. And you should save it.
Nevertheless you able switch off autoload relations and retrieve them as needed.
It is well described in documentation.
If you already know “parent” objectId, you do not need to lookup that object. You should be able to create an instance of “peopleNames” class, populate its objectId, assign the related object and save that peopleNames object. It should work, please give it a try and let us know.
Thanks for you reply … Yes I did that and but I couldn’t save the Object by knowing its ObjectId without overwriting the other values of that Object … so I guess what I need is a away to update the links in both tables without touching the other values of the Related Object … is that possible ?
It should be possible if you use the Dictionary approach - that is persisting your object as a dictionary rather than an instance of a specific class. Do you need an example for Obj-C or Swift?
In your case, you would put the “objectId” property in the “parent” object as well as a property for the relation. The related object can also be NSDictionary. Make sure to put the “___class” property with the name of the related table into the related dictionary.
the update API is working now , apparently in addition to including the objectId in the “sid” flag , also we need to add the “objectId” key in the entity dictionary .
Just a suggestion… Maybe these details about iOS platform examples to save Data Object as Dictionary items need to be documented somewhere (maybe its there but I couldn’t find it )
I am glad it worked for you. The docs are in progress - we updated the Android API about the addition of the dictionary-based support and the iOS are next.