Steve DeRienzo
Steve DeRienzo

Reputation: 237

How to return multiple findObjectsInBackground in a PFTablequery

I am trying to load my PFQueryTableViewController with this query..it keeps coming back blank... I dont think I'm returning the query right.. I don't know how to access the objects from the "secondQuery" that is WITHIN the "AdminQuery"..

thanks in advance!

  func queryForTable() -> PFQuery {

let getAdminquery = PFQuery(className: "Employee")
getAdminquery.whereKey("companyEmployee", equalTo: PFUser.currentUser()!.objectId!)
getAdminquery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

  if error == nil {

    if let objects = objects as? [PFObject] {

      for object in objects {

        let adminFollowingUser = object["companyAdmin"]  as! String

        let secondQuery = PFQuery(className:"PoolAccount")

        secondQuery.whereKey("userId",equalTo:adminFollowingUser)
        secondQuery.findObjects()

      }
    }
  }
}

return getAdminquery //return secondQuery can't be called...
  }

Upvotes: 0

Views: 572

Answers (1)

Mattias
Mattias

Reputation: 415

As Patrick Lynch states, you're defining a function inside a closure. I don't think you need that dispatch_async, since the PFQueryTableViewController already does the job for you. queryForTable()should not be inside viewDidLoad either.

Define which class you want the table to display, is it PoolAccount? PFQueryTableViewControllers queryForTable does only support returning a single query. However, if your classes are related you might be able to do it anyway, with PFQuery(orQueryWithSubqueries) and the query.includeKey().

Note: However, when you do figure out how to get the method to run properly, you're creating objects.countqueries in the for-loop. If the first query get 200 results, you want to run another 200 queries? That will probably exceed your request limit to Parse.com.

Instead, consider storing all adminFollowingUser in an array, and query the PoolAccount with .whereKey("key", containedIn: YourArray), or similar.

Upvotes: 1

Related Questions