0

In Parse Server, say I have School class, which has courses relation. as shown in the picture

Parse Server School class

What I want here is to get all schools including the courses relation. BUT, it should NOT include all columns of Course class. only objectId column.

Reason: for performance. I want to get all schools with courses ids of every school, to count them. If i loaded the whole Course object, the query maybe gets slow.

This is my code:

        // create query
        let query = PFQuery(className:"School")        

        query.includeKey("Courses")
        query.limit = 50

        query.cachePolicy = PFCachePolicy.networkElseCache
        query.findObjectsInBackground { (objects: [PFObject]?, error)-> Void in

            if error == nil {

                // The find succeeded.
                print("Successfully retrieved \(objects!.count) school.")


                // TODO: get courses count


            } else {
                // Log details of the failure
                print("Error: \(error!) \(error!)")
            }
        }

So, I need to get the courses count of every school without loading the whole course objects, only loading objectIds of courses, to make the query super fast

Thanks

Hatim
  • 1,516
  • 1
  • 18
  • 30

0 Answers0