0
votes

I have following 2 parse classes Items and categories. The Items class have a column named category which is a pointer and points to a specific id in the categories in the class. However when i want to retrieve the data from a category through this pointer it only return following:

<Categories: 0x7ffddac633b0, objectId: dHbrk97s97, localId: (null)> {
}

which is strange since categories class contain a name, createdAt and updatedAt? why are these not shown in this object?

Full code

func retrieveData() {
    //Query Item Information
    var query = PFQuery(className:"Items")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {
            // The find succeeded.

            // Do something with the found objects
            if let objects = objects as? [PFObject] {

                self.collectionView.reloadData()

                for object in objects {

                    var itemId = object.objectId!
                    var description = object["description"]! as! NSString
                    var createdAt = object.createdAt!
                    var title = object["title"]! as! NSString
                    var price = object["price"]! as! Int
                    var category = object["category"] as! PFObject


                    println(category)

                    //Query image
                    var query = PFQuery(className:"Images")
                    query.whereKey("imageId", equalTo:itemId)
                    query.whereKey("primaryImage", equalTo:true)
                    query.findObjectsInBackgroundWithBlock {
                        (objects: [AnyObject]?, error: NSError?) -> Void in

                        if error == nil {
                            // The find succeeded.
                            // Do something with the found objects
                            if let images = objects as? [PFObject] {
                                for image in images {
                                    //var primaryImage = image[]
                                }
                            }
                        } else {
                            // Log details of the failure
                            println("Error: \(error!) \(error!.userInfo!)")
                        }
                    }

                }


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

}
2
are Items and Categories classes created by you? I mean, are these custom classes? - Amit Singh
it is database classes in parse, which i've created - Peter Pik

2 Answers

0
votes

Try adding the include method after you initialize the Items query:

var query = PFQuery(className:"Items")
query.includeKey("category")

This method retrieves the specified key when the fetch on the query is triggered.

https://parse.com/docs/ios/guide#queries-relational-queries

0
votes

@peter

As you have already written that you have two parse classes created by yourself in parse database. You can call these classes as custom classes or model classes, so whenever you want to print the value of the attributes of any model class you have to NSLog() the attribute value like in your case: (in Objective-C)

Categories* catObj = [[Categories alloc] init];

NSLog(@"Name: %@, Created At:%@, Updated At:%@", catObj.name, catObj.createdAt, catObj.updatedAt);