How do I update related data for the current user?

I have a “ProfileDetails” table connected to my user table which has a field called “relatedPhoto”.

How do I update this relatedPhoto field for the currentUser? I have an async function uploading an image to backendless and returning a URL, now I just need to set the “relatedPhoto” field in this related table with this new url value.

This is my code for a field that’s in the user table. Just wondering how it would work for a related table field:


uploadProfilePhoto(photo!, result: { (imageLink) in
    let properties = ["photo" : imageLink!]
    registeredUser.updateProperties(properties)
    
    backendless.userService.update(registeredUser, response: { (updatedUser: BackendlessUser!) in
        print("Uploaded photo")
    }, error: { (fault: Fault!) in
            print("error during photo upload: \(fault)")
    })
})

Hello,
BackendlessUser is a regular object and you can update it like any other object. I can recommend you to follow the doc https://backendless.com/documentation/data/js/data_relations_save_update.htm. If you encounter any difficulties don`t hesitate to ask.
Artur.

Thanks. Can you tell me how I’d use user.updateProperties(properties) to update the data in a related object?

I’m sorry, did I post this in the wrong area? This is an iOS swift question.

Sorry, I have missed the language. The next time you create post on support please specify the language in topic.
I have assigned your topic to iOS/Swift developer.

Please provide here your ProfileDetails class and its user property name.

This is my ProfileDetails class. It is a one to one relation from BackendlessUser:









class ProfileDetails: NSObject {

    var title: String?

    var company: String?

    var jobTitle: String?

    var websiteurl: String?

    var profileDescription: String?

    var relatedPhoto: String?

}

First, switch on the ‘autoload’ checkbox on relatedPhoto field of Users table. This allows it will be loaded with user object.

Here is a code:

    func uploadProfilePhoto(registeredUser: BackendlessUser, imageLink : String) {
        
    registeredUser.setProperty("photo", object: imageLink)
    
    var photoRel = registeredUser.getProperty("relatedPhoto") as? ProfileDetails
    if photoRel == nil {
        photoRel = ProfileDetails()
        registeredUser.setProperty("relatedPhoto", object:photoRel)
    }
    photoRel!.relatedPhoto = imageLink
    
    backendless.userService.update(
        registeredUser,
        response: { (updatedUser: BackendlessUser!) in
            print("Uploaded photo")
        },
        error: { (fault: Fault!) in
            print("error during photo upload: \(fault)")
        })
    }


Thanks, that helped!

You’re welcome, you could investigate this doc. Hope BlogFeatureDay project also will be helpful for you.