Apollo
Apollo

Reputation: 9064

or query with include

I have a join table with a from column and a to column. Both columns point to user objects. When perform this OR query, it throws the error: 'OR queries do not support sub-queries with includes'

Is there any way around this? Thanks!

// set up query to get all relationships where the current user friended another user.

PFQuery *userIsFriendSender = [PFQuery queryWithClassName:@"UserRelationships"];
[userIsFriendSender whereKey:@"from" equalTo:[PFUser currentUser]];
[userIsFriendSender whereKey:@"active" equalTo:@YES];

[userIsFriendSender includeKey:@"to"];

// set up query to get all relationships where a use friended the current user
PFQuery *userIsFriendReceiver = [PFQuery queryWithClassName:@"UserRelationships"];
[userIsFriendReceiver whereKey:@"to" equalTo:[PFUser currentUser]];
[userIsFriendReceiver whereKey:@"active" equalTo:@YES];

[userIsFriendReceiver includeKey:@"from"];

PFQuery *query = [PFQuery orQueryWithSubqueries:@[userIsFriendSender, userIsFriendReceiver]];

Upvotes: 6

Views: 769

Answers (1)

Worakarn Isaratham
Worakarn Isaratham

Reputation: 1034

Try moving includeKey: clauses to the joint query.

PFQuery *query = [PFQuery orQueryWithSubqueries:@[userIsFriendSender, userIsFriendReceiver]];
[query includeKey:@"from"];
[query includeKey:@"to"];

Upvotes: 18

Related Questions