简体   繁体   English

Parse.com如何获取所有用户的相关数据

[英]Parse.com How to get all user's related data

I have an app where I'm trying to load a User and all his related data. 我有一个应用程序正在尝试加载用户及其所有相关数据。 In the relations I have BodyTracking as one relation. 在关系中,我将BodyTracking作为一种关系。 Another is DiaryWeek, which in turn has DiaryDays (of the week). 另一个是DiaryWeek,它又具有(一周中的)DiaryDays。 I successfully pulled all the BodyTracking, but when I try the same for the DiaryWeeks, I get an error saying that I have to wait. 我成功地拉开了所有的BodyTracking,但是当我为DiaryWeeks尝试相同的操作时,出现错误,提示我必须等待。 I guess what is happening is that the BodyTracking, which is requested with 'findObjectsInBackgroundWithBlock' is still going on when the DiaryWeek request is called. 我猜发生了什么事,当调用DiaryWeek请求时,使用'findObjectsInBackgroundWithBlock'请求的BodyTracking仍在继续。 Is there a way to pull all the data in one go? 有没有办法一次性提取所有数据?

        // Body Tracking
    bodyEntries.removeAll()
    let trackingQuery = PFQuery(className: "BodyTracking")
    trackingQuery.whereKey("user", equalTo: member)
    trackingQuery.orderByDescending("trackingDate")
    trackingQuery.findObjectsInBackgroundWithBlock {
        (objects: [PFObject]?, error: NSError?) -> Void in

        if error == nil {
            print("Successfully retrieved \(objects!.count) body entries.")

            if let objects = objects! as? [PFObject] {
                for object in objects {
                    let bodyEntry = BodyTracking(object: object)
                    self.bodyEntries.append(bodyEntry)
                }
                self.bodyTrackingTableView.reloadData()
            }
        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)")
        }
    }

    // Food Diary
    foodWeeks.removeAll()
    let diaryQuery = PFQuery(className: "FoodDiaryWeek")
    diaryQuery.whereKey("user", equalTo: member)
    diaryQuery.orderByDescending("weekStartDate")
    trackingQuery.findObjectsInBackgroundWithBlock {
        (objects: [PFObject]?, error: NSError?) -> Void in

        if error == nil {
            print("Successfully retrieved \(objects!.count) food weeks")

            if let objects = objects! as? [PFObject] {
                for object in objects {
                    let foodWeek = FoodDiaryWeek(object: object)
                    self.foodWeeks.append(foodWeek)
                }
            }
        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)")
        }
    }

Error message: This query has an outstanding network connection. 错误消息:此查询具有出色的网络连接。 You have to wait until it's done. 您必须等待,直到完成。

It looks like you are accidentally executing the trackingQuery twice. 它看起来像你不小心执行trackingQuery两次。 The diaryQuery is never executed. diaryQuery永远不会执行。 Maybe a copy/paste error (?) 可能是复制/粘贴错误(?)

   // Food Diary
foodWeeks.removeAll()
let diaryQuery = PFQuery(className: "FoodDiaryWeek")
diaryQuery.whereKey("user", equalTo: member)
diaryQuery.orderByDescending("weekStartDate")
**trackingQuery**.findObjectsInBackgroundWithBlock {

replace trackingQuery by diaryQuery 用diaryQuery替换trackingQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM