Reputation: 14722
I created my classes and inserted some data into them on Parse.com using a browser. Basically, I created classes A and B. A has a column of type B.
Now I want to display that data in my app. I am using the following code to get class A which is working fine.
let query = PFQuery(className:"A")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error == nil {
// Do stuff
} else {
print("Error: \(error) \(error!.userInfo)")
}
}
However, I am not able to get class B data. I tried the following
query.includeKey("B")
This throws an error saying this is not a pointer relationship.
I also tried
let bObjects = aObject.objectForKey("B") as? [PFObject]
But the result is nil.
Question: How do I get 'many' objects in a one-to-many relationship in Parse?
Upvotes: 0
Views: 55
Reputation: 14722
This is how I implemented the accepted answer:
let bObjectsRelation = self.relationForKey("B")
bObjectsRelation.query()?.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error == nil {
let bObjects = objects! as [PFObject]
} else {
print("Error: \(error) \(error!.userInfo)")
}
}
Upvotes: 0