GuiSoySauce
GuiSoySauce

Reputation: 1783

Relational queries on Parse and Swift

I am trying to get the objects that are relational to a class.

Bellow is my query:

var user = PFUser.currentUser()
println("PERSON\(user)")
var relation = user!.relationForKey("followingThings")
var queryTeste = relation.query()
queryTeste?.findObjectsInBackgroundWithBlock({ (object: [AnyObject]?, error: NSError?) -> Void in
    println("OBJECTS FROM RELATIONAL QUERY\(object)")
})

If you look at the output I am able to retrieve my relational objects, BUT... I get an error just before retrieving them.

I've tried different combinations in order to get rid of it but no success. Also most of the questions here are on objective C and sintaxe and methods differ a bit.

Any ideas about what could be causing the error?

PERSONOptional( { email = "[email protected]"; emailVerified = 1; followingThings = " Things>"; points = 10; username = Me; })

2015-08-31 19:16:32.161 App[30479:9376080] [Error]: field followingThings cannot be included because it is not a pointer to another object (Code: 102, Version: 1.8.0)

OBJECTS FROM RELATIONAL QUERYOptional([

Things: 0x7ff031a736c0, objectId: G29f9Wfqj5, localId: (null)> { description = Camping; searchKey = camping; usersFollowing = " _User>"; },

Things: 0x7ff031a76520, objectId: IPEg4G2Qec, localId: (null)> { description = "Animal Care"; searchKey = "animal care"; usersFollowing = " _User>"; },

Things: 0x7ff031a76120, objectId: Jg4oRjebKE, localId: (null)> { description = Bicycling; searchKey = bycicling; usersFollowing = " _User>"; },

Things: 0x7ff031a75810, objectId: TseQvlo6AL, localId: (null)> { description = Boating; searchKey = boating; usersFollowing = " _User>"; }])

Upvotes: 0

Views: 345

Answers (1)

Kristijan Delivuk
Kristijan Delivuk

Reputation: 1252

works for me like that

    var relation = currentUser.relationForKey("product")
                        relation.query()?.findObjectsInBackgroundWithBlock({

                            (let productResult, let error) -> Void in
                            //println("result:\(productResult!.count)")

                            if let result = productResult {
                                //println(result.count)
                                for product in result {
println(product)
}
}
}

Upvotes: 1

Related Questions