Having a hard time Querying relation, it doesn't bring up anything

Hello, I was able to successfully use whereClauses, but once I tried relations, I always get the message
“orContacts have been found: []” (this is supposed to indicate that the function worked, and retrieved objects), essentially nothing. Any help appreciated, thank You. I’ve inculed an attatchment of my datatable.
[iOS] [Swift]
class Users : NSObject {

var email: String?
var lastLogin: String?
var name: String?
var objectId: String?
var ownerId: String?
var created: NSDate?
var updated: NSDate?

}
class Groups : NSObject {
var groupName: String?
var UsersInGroup: [Users] = []
var objectId: String?
var ownerId: String?
var created: NSDate?
var updated: NSDate?
}
import UIKit
class GroupsTableViewController: UITableViewController /* UITableViewDataSource, UITableViewDelegate */ {

let APP_ID = “E72B859C-6C84-6141-FF84-00946A6FC800”
let SECRET_KEY = “617441C6-03FC-FCC8-FF82-9A3F97B81D00”
let VERSION_NUM = “v1”

var backendless = Backendless.sharedInstance()

@IBOutlet weak var table: UITableView!

var items=[“Dog”,“Cat”,“Cow”,“Platypus”]

override func viewDidLoad() {
super.viewDidLoad()

backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
self.backendless.userService.getPersistentUser()
let user = self.backendless.userService.currentUser
if (user == nil) {
Utilities.loginUser(self)
} else {
self.loadData()
}

findGroupsUserIsIn()

self.table.registerClass(UITableViewCell.self, forCellReuseIdentifier: “cell”)
self.table.dataSource = self
self.table.delegate = self
}

func findGroupsUserIsIn() {

let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = “Groups[UsersInGroup].objectId =‘A0831585-716E-B027-FF37-539497748400’”

var error: Fault?

let bc = backendless.data.of(Users.ofClass()).find(dataQuery, fault: &error)
if error == nil {
print(“Contacts have been found: (bc.data)”)
}
else {
print(“Server reported an error: (error)”)
}
}

Creating class Users is a bad idea. You should use the BackendlessUser class to work with the data in the built-in Users table. I suspect it leads to the problems you’re experiencing.

Regards,
Mark

Thanks for your reply,

How would I add a relation from the Groups table to the BackendlessUser? Instead of creating a users class?

Thank you.

Hi Lekan,

You can do it like this:

class Groups : NSObject {
var groupName: String?
var UsersInGroup: [BackendlessUser] = []
var objectId: String?
var ownerId: String?
var created: NSDate?
var updated: NSDate?
}

Regards,
Mark

Thank you very much.

I still get “Contacts have been found: []”
Here is my query

func findGroupsUserIsIn() {

    let user = backendless.userService.currentUser
    
    
    let dataQuery = BackendlessDataQuery()
    dataQuery.whereClause = "Groups[UsersInGroup].objectId ='user.objectId'"

    
    var error: Fault?
    let bc = backendless.data.of(BackendlessUser.ofClass()).find(dataQuery, fault: &error)
    if error == nil {
        print("Contacts have been found: \(bc.data)")
    }
    else {
        print("Server reported an error: \(error)")
    }
}

Got it to work.

func findGroupsUserIsIn() {

    

    self.backendless.userService.getPersistentUser()

    let user = self.backendless.userService.currentUser

    print(user.objectId)




    

    let whereClause = "UsersInGroup.objectId = '\(user.objectId)'"

    let dataQuery = BackendlessDataQuery()

    dataQuery.whereClause = whereClause

    

    var error: Fault?

    let bc = self.backendless.persistenceService.find(Groups.ofClass(),

        dataQuery:dataQuery) as BackendlessCollection




    if error == nil {

        for test in bc.data as! [Groups] {

            print(test.groupName)

        }

    

    }

    else {

        print("Server reported an error: \(error)")

    }

}