我想用作我的应用 Parse 的后端,并假设我有一个包含不同餐厅的类,每个餐厅的菜单和每个菜单不同的产品,我有一个类 Place、Menu、Product 和 MenuItems:
MenuItem 类有: Pointe menu 指针产品
菜单类:指针位置
选择餐厅后,必须显示该餐厅的所有产品: 我的代码:
PFQuery *query = [PFQuery queryWithClassName:@"Places"];
[query whereKey:@"name" equalTo:PlaceSelect];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFObject *Menu;
if (!error)
{
for (PFObject *ob in objects)
{
Menu = ob;
}
}
PFQuery *query1 = [PFQuery queryWithClassName:@"Menus"];
[query1 whereKey:@"place" equalTo:Menu];
[query1 findObjectsInBackgroundWithBlock:^(NSArray *objects2, NSError *error2) {
PFObject *MenuItems;
if (!error2)
{
for (PFObject *ob2 in objects2)
{
MenuItems = ob2;
}
}
PFQuery *query2 = [PFQuery queryWithClassName:@"MenuItems"];
[query2 whereKey:@"menu" equalTo:MenuItems];
[query2 selectKeys:@[@"product"]];
[query2 findObjectsInBackgroundWithBlock:^(NSArray *objects3, NSError *error3) {
PFObject *Products;
if (!error3)
{
for (PFObject *ob3 in objects3)
{
Products = ob3;
NSLog(@" %@ ",Products);
}
我得到相关产品,但是当我想按类型过滤时:饮料、开胃菜等......它给了我所有地方的所有产品......
PFQuery *retrievedDrink = [PFQuery queryWithClassName:@"Products"];
[retrievedDrink whereKey:@"type" equalTo:@"drink"];
[retrievedDrink whereKey:@"objectId" equalTo:Products.objectId];
[retrievedDrink findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
DrinksArray = [[NSArray alloc] initWithArray:objects];
NSLog(@"numero de productos Drinks= %i ",[DrinksArray count]);
}];
在此先感谢,如果有人知道更有效的方法,我想澄清我的疑问