Support Topics Documentation Slack YouTube Blog

Autoload Relations with BackendlessUser Parent

With 6.0 removing the Autoload box in console, how do you autoload a child object when a user logs in?

Swift SDK

You would need to use the following API call to retrieve object’s (in your case current user) relations:
https://backendless.com/docs/ios/data_two_step_retrieval.html

Regards,
Mark

Thanks Mark. Unfortunate we cant do it in a single call anymore.

But there is a bug in this api, I believe its related to internal ticket BKNDLSS-21340
Unable to cast to class
attached is a example

Broken.zip (875.4 KB)

Hi Robert,

21340 was closed back in May. Are you using the latest version of our SDK?

Regards,
Mark

yes, 6.0.1.1.

Just a hunch they are related, since same crash on a Dif API

@olhadanylova, please take a look at the example attached here.

Hello,
I’ll check it as soon as possible.

Regards,
Olha

@robert-j,
in your example you use LoadRelationsQueryBuilder for the BackendlessUser class and dataStore for the BEUserProperty.
According to the documentation, your LoadRelationsQueryBuilder should refer to the BEUserProperty class and dataStore - to the BackendlessUser instead.
Please fix your read() code to:

func read() {
    let queryBuilder = LoadRelationsQueryBuilder(entityClass: BEUserProperty.self, relationName: "test")
    let dataStore = Backendless.shared.data.of(BackendlessUser.self)
    dataStore.loadRelations(objectId: Backendless.shared.userService.currentUser?.objectId ?? "", queryBuilder: queryBuilder, responseHandler: { attachedUser in
        print(attachedUser[0])
        let user = attachedUser[0] as! BEUserProperty
        print(user)
    }, errorHandler: { fault in
        print("Error: \(fault.message ?? "")")
    })
}

Regards,
Olha

Ooops, thanks Olha!