0

i have successfully made the relation. now i dont know how to query it i can see the data on the website og i can see it's linked to each-other

Here's how i make the "link" 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

Here's how i make the query "which isn't working"

 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)")

                    }
                }
            }
KennyVB
  • 745
  • 2
  • 9
  • 28

1 Answers1

0

The problem with relations is that you cannot use existing data fields, if there is a relation field, you have to create new fields that are visible only for that row. So until that, the query won't show you anything.

Dániel Nagy
  • 11,815
  • 9
  • 50
  • 58