我有一个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;
这让我得到了所有产品,而不是现在的商店。但是每个商店都有产品,所以它们会重复出现。
如何对它们进行排序以使它们不同?
答案 0 :(得分:-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只包含不同的产品。