Ambiguous reference to member 'locations'

Hi Guy`s

I try to repeat this tutorial: https://backendless.com/feature-28-loading-related-data-objects-the-semi-lazy-approach/

But in line:

self.printLocations(restaurant.locations as [Location])

I will have a error: Ambiguous reference to member ‘locations’
How can I fix that?

import UIKit




class Restaurant : NSObject {

    var locations : [Location]?

}




class Location : NSObject {

    var streetAdress : String?

    var city : String?

}




class Load: UIViewController {

    

    var backendless = Backendless.sharedInstance()




    override func viewDidLoad() {

        super.viewDidLoad()

        

        self.twoStepsLoadRelationsSync()

    }




    func twoStepsLoadRelationsSync() {

        

        Types.tryblock({ () -> Void in

            var query = BackendlessDataQuery()

            var restaurants =           self.backendless.persistenceService.of(Restaurant.ofClass()).find(query)

            

            var currentPage = restaurants.getCurrentPage()

            print("Loaded \(currentPage.count) restaurant objects")

            print("Total restaurants in the Backendless starage - \(restaurants.totalObjects)")

            

            for restaurant in currentPage {

                self.backendless.persistenceService.load(restaurant, relations:["locations"])

                print("Restaurant name = \(restaurant.name)")

                self.printLocations(restaurant.locations as [Location])

            }

            }) { (exception) -> Void in

                print("Server reported an error: \(exception as! Fault)")

        }

    }

    

    func printLocations(locations: [Location]?) {

        

        if locations == nil {

            print("Restaurant locations have not been loaded")

            return

        }

        

        if locations?.count == 0 {

            print("There are no related locations")

            return

        }

        

        for location in locations! {

            print("Location: Street address - \(location.streetAdress), City - \(location.city)")

        }

    }

}

Hi Pascal,

Please try the latest release of this sample in BlogFeatureDay-iOS github.

Regards,
Slava

With the new tutorial it works fine. Thanks.
It will retrieve all objects in Location. How can I right now filter that?
Like: User logged in, retrieve all object in Location witch is in related with Restaurant(Starbucks)
I hope you understand what I mean.

You should use BackendlessDataQuery.whereClause.

Here is guide for Advanced Object Retrieval, please investigate it.

Thanks. How can I retrieve data witch is in a relationship with the Users class?

You need to use the getProperty method on the BackendlessUser object.

Do you have some good tutorials witch are explaining that?

It is right in the documentation:

https://backendless.com/documentation/users/ios/users_user_properties.htm

I understand that. But it shows only how to retrieve “normal” data. How can I retrieve relationships?

You can use the following approach to retrieve user objects. The "query "argument would control the relations:
self.backendless.persistenceService.of(BackendlessUser.ofClass()).find(query)

More details are in the documentation:https://backendless.com/documentation/data/rest/data_relations_retrieve.htm

Sorry it is so difficult to understand that and the documentation are also not so helpful. Does some videos exist or is a webinar in planing?

I am right now 3 weeks on it and I am just one step closer to understand how I can retrieve a row in Location Class witch is in relation with Restaurant with is in relation with Users (Users->Restaurant->Location)

Do you already have the user object for who you need to loads the restaurant and location?

I will retrieve the data always for the current user.

But I am not sure if you mean that.

If you know objectId of the user for whom you need to load restaurant objects, then you should do the following:

    Send your query to the Restaurant table. That means in the of() method you put Restaurant.ofClass() Set the where clause to: Users[restaurants].objectId = 'objectId-of-the-user-to-get-restaurants-for' This will get all the restaurants of the user in question

    Add query options to the BackendlessDataQuery object with related column for the location (the documentation describes that)

Regards, Mark