如何进行prober PFRelation查询? Parse.com

时间:2015-01-01 10:07:38

标签: swift parse-platform ios8 pfrelation

我已成功建立了这种关系。现在我不知道如何查询它 我可以看到网站上的数据og我可以看到它与其他

相关联

以下是我如何制作“链接”PFRelation

 var query = PFQuery(className:"Profile")
    let objectID = data.valueForKey("objectId") as String?
    query.getObjectInBackgroundWithId(objectID) {
        (rodObj1: PFObject!, error: NSError!) -> Void in
        if error == nil {
            let dateFormatter = NSDateFormatter()
            dateFormatter.dateFormat = "MMM-d-yyyy HH:mm:ss zzz"
            let str1 = dateFormatter.stringFromDate(NSDate())
            var dateFromString1 = dateFormatter.dateFromString(str1)




            var profil = PFObject(className: "SwitchColor")
            profil["Rod"] = dateFromString1
            println("Profil = ********\(profil)")
            profil.saveEventually()
            let rod: PFRelation = rodObj1.relationForKey("SwitchColor")
            rod.addObject(profil)
            println("rodObj = *********\(rod)")
            rodObj1.saveEventually()
        }
    }

enter image description here enter image description here

以下是我如何使查询“哪个不起作用”

 let rodobj: PFObject = PFObject(className: "Profile")
            let relationRod: PFRelation = rodobj.relationForKey("SwitchColor")
            let query: PFQuery = relationRod.query()
            query.orderByDescending("createdAt")
            query.findObjectsInBackgroundWithBlock{(objQ: [AnyObject]!, error: NSError!) -> Void in
                if let staffObjects = objQ as? [PFObject] {
                    for staff in staffObjects {
                       self.countObj.addObject(staff)
                        staff.pin()
                        self.barChart.reloadData()
                        dispatch_async(dispatch_get_main_queue(), {
                            self.tableView.reloadData()
                            self.refreshControl.endRefreshing()
                        })
                        println("countObj: \(self.countObj.count)")

                    }
                }
            }

1 个答案:

答案 0 :(得分:0)

关系问题在于您无法使用现有数据字段,如果存在关系字段,则必须创建仅对该行可见的新字段。所以在此之前,查询不会向您显示任何内容。