Start a new topic

Relational data problem

Hi,

I'm trying to implement relational logic and everything looks find until I try to retrieve and then save data.

If I have some relational data and resolve them the _obj is not empty and if I then try to save the parent object I have a problem because _obj is saved too what is kind of weird because this data should live in the separate collection. Firstly it seemed to me that your backend is smart enough to prevent saving _obj but I was wrong, it saved. So now I have to remove all the inner _obj objects before saving and then retrieve the parent object from database to restore data.

Can you propose less terrible solution because each time when I want to save object in DB I have to do 2 queries instead of 1 query what can be annoying for end users especially if object is big?

Thanks

Hi Kath,



While most of our libraries/SDKs will automatically handle stripping out nested references before saving, the REST API poses few restrictions on the format of your data, and as you noticed, will indeed allow you to save an entity containing an _obj property.



The REST API also does not automatically save changes made to referenced entities. One potential way to get around the extra round-trip neeed to save the referenced entity is to create a pre-save business logic hook on your collection, and in it strip out the contents of the _obj property and update the related entity. However, you should be careful with this approach, as all actions performed through BL are executed with master credentials which, depending on your use case and implementation, may pose a security risk.
Thanks, Gal,

I use some workaround.
Login or Signup to post a comment