I'm trying to do a simple query in xcode using the Parse SDK where I am showing products to users but i don't want to show them products they've already "liked."
So I have two tables in Parse that I'm using:
- Products: has an objectId
- Likes: contains columns: Like (says yes/ no), Pointer to a product, Pointer to a user
Any my code is:
//query will get products that the user has liked
PFQuery *likeQuery = [PFQuery queryWithClassName:@"Likes"];
[likeQuery whereKey:@"User_Obj" equalTo:[PFUser currentUser]];
//product query will get products that are not in like query
PFQuery *prodQuery = [PFQuery queryWithClassName:@"Products"];
[prodQuery whereKey:@"objectID" doesNotMatchKey:@"Product" inQuery:likeQuery];
//restrict to 10 items
[prodQuery setLimit:10];
[prodQuery findObjectsInBackgroundWithTarget:self
selector:@selector(getCallback:error:)];
However, when I try and run this previously liked items by that user are being returned.
If i were doing this in SQL I would write something like:
SELECT product FROM product WHERE product NOT IN (SELECT product FROM likes WHERE useriD = currentUser AND like = yes)
Any help would be much appreciated!
Thanks, Tim