Problem with change of related objects

Hello

I have a simple problem with synchronisation of changes objects. I have a list of objects, I show one object on another screen and update several related objects. I can create new related object and can’t remove this object without full reload object from backendless. With this problem I have to give object from response and change(remove/update) related objects in new object that I get from response. But I have another list that I get when application was started and this list I have to full reload? Why I get new object in response?

Thanks
Sergey

Sergey,

Sorry, I am having hard time following what you’re doing by reading the description of the problem. Any chance you could demonstrate the problem with some sample code (please, no full listings from your app, just a snippet demonstrating the problem)

Mark

Hello Mark,

My sample code. This code can not work but can explain that I do. company is object of “Company” class. company have related tags. Tags have autoload check in Backendless DB. When I append tag and save company than tag add to Backendless DB. But when I try remove this tag than I have error message about “Can’t remove because Object with this objectID not have in persistent storage”. How I understand I have to save Tag, after it append to company and save company, and update all object that used first created tag?

let tag = Tag()
tag.name = tagName!
company?.tags.append(tag)
Backendless.sharedInstance().persistenceService.save(company, response: { [weak self] (company) in
            //.....
            Backendless.sharedInstance().persistenceService.remove(tag)


        }) { [weak self] (fault) in
            //.....
        }

Thanks
Sergey

Hi Sergey,

You do not need to save tag first. You can create a Tag object, append it to the company and save the company. That will create/update company and also create tag.

Is your question how to remove a tag from a company?

Mark

I have to questions:

  1. Why when I save “company” in response I have another “company”. Same with previous company but it’s another object.
  2. Yes. I can’t remove a tag from a company. I use “remove” method in persistentService. All work good when I load a company list from server and remove a tag, but if I create a tag and after it I try remove this tag without reload a company from a server then I have message about “object with this objectID don’t exist”
  1. That’s just how it works. Passing the same object (especially in the asynchronous APIs, which means an object must “travel” to the server and then back to the client in a different thread) adds a lot of unnecessary complexity.

  2. To remove a tag from a company, you need to: (1) load company object from the server with related tags, (2) remove a tag from the collection of tags, (3) save the company object

Thank you, Mark. I understand.
It’s create several problems if application work in several threads and make a lot of tasks in one time. Plus if you use object at the one screen(for example: show list of objects) and in this time change this object at the another screen. When user back to main a list of objects then application have not actual data. Application have to reload all objects. When Application have a lot of objects (for example, more than 1000), application have to reload all this objects or add business logic for fix this conflict.

I understand why you or your developers don’t make synchronisation objects. I offer to think about synchronisation in the future. It’s fix a lot of problem.

Thanks for you help, Mark

Have a nice day
Sergey