0

我有一个带有一些表的 parse.com 后端:

shop
product
shopHasProduct
  Shop:Shop Pointer;
  Product:Product pointer; 
  + some fields relation to shop-specific info

shopHasProduct多对多表也是如此。

我需要的是获取所有product不在shopHasProduct特定表中的shop.

到目前为止我所做的是(查询在shopHasProduct表上):

[query whereKey:@"Shop" notEqualTo:[[PFUser currentUser] objectForKey:@"currentShop"]];
[query includeKey:@"Product"];

PFQuery *shopHasProductThisShop = [[PFQuery alloc] initWithClassName:@"shopHasProduct"];
[shopHasProductThisShop whereKey:@"Shop" equalTo:[[PFUser currentUser] objectForKey:@"currentShop"]];

PFQuery *finalQ = [[PFQuery alloc] initWithClassName:@"shopHasProduct"];
[finalQ whereKey:@"Product" doesNotMatchKey:@"Product" inQuery:shopHasProductThisShop];
[finalQ includeKey:@"Product"];

return finalQ;//query;

这让我得到了所有不在当前商店的产品。但是每个商店都有产品,所以它们会重复出现。

我如何对它们进行排序以使它们不同?

4

1 回答 1

-2

我最终没有使用PFQueryTableViewController,而是正常的UITableViewController

在 viewDidLoad 我执行以下操作:

PFQuery *shopHasProductThisShop = [[PFQuery alloc] initWithClassName:@"shopHasProduct"];
[shopHasProductThisShop whereKey:@"Shop" equalTo:[[PFUser currentUser] objectForKey:@"currentShop"]];



PFQuery *hej = [[PFQuery alloc] initWithClassName:@"shopHasProduct"];
[hej whereKey:@"Product" doesNotMatchKey:@"Product" inQuery:shopHasProductThisShop];
[hej includeKey:@"Product"];

[hej findObjectsInBackgroundWithBlock:^(NSArray *allProducts, NSError *error) {

    self.productToAdd = [NSMutableArray new];
    self.productArray = [NSMutableArray new];
    NSLog(@"Hvor mange er der i alle prodikter'et:%d", [allProducts count]);

    for (PFObject *object in allProducts) {

        PFObject *random = object[@"Product"];
        [self.productArray addObject:random];

    }
    NSSet *uniqueStates = [NSSet setWithArray:[self.productArray valueForKey:@"objectId"]];

    NSArray *foobar = [uniqueStates allObjects];
    for (NSString *string in foobar) {
        PFObject *hulo = [PFQuery getObjectOfClass:@"Product" objectId:string];
        [self.productToAdd addObject:hulo];
    }  
   [self.tableView reloadData];
}];

所以我得到了一个只有不同产品的 NSMutableArray。

于 2013-11-08T13:32:26.047 回答