Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]];
like image 337
Apollo Avatar asked Nov 25 '13 06:11

Apollo


1 Answers

Try moving includeKey: clauses to the joint query.

PFQuery *query = [PFQuery orQueryWithSubqueries:@[userIsFriendSender, userIsFriendReceiver]];
[query includeKey:@"from"];
[query includeKey:@"to"];
like image 130
Worakarn Isaratham Avatar answered Nov 09 '22 04:11

Worakarn Isaratham