Support Topics Documentation Slack YouTube Blog

Relations Master 4/5 "Retrieve related data with API

Mission: Relations Master 4/5
Task: “Retrieve related data with API”

In SWIFT, the program works and seems to do the job, but it does not pass the test. Where is the problem please ?

var myTable = “Person”

@IBAction func pushButtonFindItemInCity(_ sender: Any) {
    let dataStore = Backendless.shared.data.ofTable(myTable)

    let queryBuilder = DataQueryBuilder()
    queryBuilder.setRelated(related: ["cityOfResidence", "cityOfResidence.City"])

    dataStore.findById(objectId: self.myObject["objectId"] as! String, queryBuilder: queryBuilder, responseHandler: { foundObjects in

        print("Found \(foundObjects.count) objects: \(foundObjects)")
    }, errorHandler: { fault in
        print("Error: \(fault.message ?? "")")
    })
}

Hi Sylvain,

Welcome to the Backendless community.

To get the task recognized, I recommend modifying the code so it is as close as possible to the logic demonstrated in the task’s instructions. You will see that the example in the instructions uses a where clause to identify the parent object. Also, the relation is only cityOfResidence (while your code puts two relations in there).

Hope this helps.

Regards,
Mark