Carmichael
Carmichael

Reputation: 467

Parse.com relational query issue

I have the following tables name "aniStudii" and "discipline", I have made a screenshot as well:

enter image description here

As you can see, there is a relation between these tables, at the "materii" column. The row from "aniStudii" with the column "Anul I" has a value and the other column has a different value, values that can be found in the "discipline" table.

I am using this query to get the values, but all I get is Error: bad pointer for key: _p_materii (Code: 106, Version: 1.2.8)

This is my query:

PFQuery *query = [PFQuery queryWithClassName:@"aniStudii"]; //1
PFObject *aniStudiu = [PFObject objectWithClassName:@"discipline"];
[query whereKey:@"materii" equalTo:aniStudiu];

[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
    NSLog(@"%@",results);
}];

Where is the problem? A big thanks in advance.

Upvotes: 2

Views: 2448

Answers (1)

Wain
Wain

Reputation: 119021

Do something like this, where you start from a specified object (which you may need a query to find):

PFObject *sourceObject = ...;

PFRelation *relation = [sourceObject relationforKey:@"materii"];

[[relation query] findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
    NSLog(@"%@",results);
}];

To get the first object you can perform a query something like:

PFQuery *query = [PFQuery queryWithClassName:@"aniStudii"];
[query whereKey:@"numeAn" equalTo:@"######"];

Upvotes: 2

Related Questions