Lost of ownerId value after updating and saving an object

Hello,

Using the iOS SDK (from github, cloned less than a week ago)

with appID AEE7E37E-51C0-8032-FF1F-11FD36B99D00,

I have a single class “UserAddress”. I want to use its field “ownerId” as the relation with the User object.

I have a unitary test file in my XCode project to test :

  • register a user
  • login the user
  • save a UserAddress object
    => I see the value of the ownerId field (first screenshot)
  • I update the UserAddress object (setting the value of the INT customerId field)
  • save the UserAddress object again
    => I see the value of the updated customerId field, but the ownerIf field has disappeared (second screenshot)

Is there an logical explanation to that issue ?

I isolated the unitary test in a minimalist project, without any additional code, that may allow you to reproduce the problem. I’m going to send a link to download this minimalist project to support@backendless.com.

  • Open the project
  • open the BackendlessTest.m
  • run the test with CMD+U
  • use the breakpoints to check the value of ownerId in the UserAddress table, from the dashboard

I’ve noticed another small problem, one I can live with:
in the UserAddress table, I have a column STRING countryCode.

When I save the object, the text for this field is automatically converted to uppercase string.

loïc b.

Hi loïc,

The problem with ownerId lays in your WRONG scenario of data processing:

  1. you save an original object, then set its ‘objectId’ from the saved object in the server response.
  2. you change the property of the original object, then update it on the server.

The main rule is “don’t change objectId manually”.

The RIGTH scenario is:

  1. you save the original object, get the saved object from the server response - and now it is the actual object you’ll operate with.
  2. you change the property of the saved object, then update it on the server.

Here is a sample demonstrating the right scenario (in swift):

    func updateSavedObject() {
        
        let phoneBook = PhoneBook()
        let contact = Contact()
        phoneBook.contacts = [contact]
        phoneBook.status = 0
        
        var error: Fault?
        let created = Backendless.sharedInstance().data.save(phoneBook, error: &error) as? PhoneBook
        if error == nil {
            print("PhoneBook has been saved: \(created!.objectId)")
            
            // - RIGHT
            created!.status = 50
            
            var error: Fault?
            let updated = backendless.data.update(created, error: &error) as? PhoneBook
            if error == nil {
                print("PhoneBook has been updated: \(updated!.objectId)")
            }
            else {
                print("Server reported an error: \(error)")
            }
            //
            
            /* - WRONG
            phoneBook.objectId = created?.objectId
            phoneBook.status = 50
            
            var error: Fault?
            let updated = backendless.data.update(phoneBook, error: &error) as? PhoneBook
            if error == nil {
                print("PhoneBook has been updated: \(updated!.objectId)")
            }
            else {
                print("Server reported an error: \(error)")
            }
            */
        }
        else {
            print("Server reported an error: \(error)")
        }
    }

Regards,
Slava