解析PFQuery包含密钥不起作用

时间:2015-01-14 05:13:40

标签: ios parse-platform

我有一个班级,商业:

头:

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface Business : PFObject <PFSubclassing>

+ (NSString *)parseClassName;
@property (retain) NSString *name;
@property (retain) NSString *shortName;
@property (retain) PFFile *logo;
@property (retain) PFFile *banner;

@end

实现:

#import "Business.h"
#import <Parse/PFObject+Subclass.h>

@implementation Business

@dynamic name;
@dynamic shortName;
@dynamic logo;
@dynamic banner;

+ (NSString *)parseClassName
{
    return @"Business";
}

@end

和一个班级,关系

头:

#import <Parse/Parse.h>
#import "Business.h"

@interface Relation : PFObject <PFSubclassing>

@property (retain) PFUser *user;
@property (retain) Business *business;

@end

实施

#import "Relation.h"
#import <Parse/PFObject+Subclass.h>

@implementation Relation

@dynamic business;
@dynamic user;

+ (NSString *)parseClassName
{
    return @"Relation";
}

@end

我正在建立一个关系查询,希望找到与某些用户相关的企业,如下所示:

PFQuery *query = [Relation query];
[query includeKey:[Business parseClassName]];
[query whereKey:@"user" equalTo:[PFUser currentUser]];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    NSMutableArray *businesses = [NSMutableArray array];
    if (objects.count) {
        for (Relation *relation in objects) {
            [businesses addObject:relation.business];
        }
    }

    block(businesses, objects, error);
}];

看来我成功检索了我想要检索的商家。但是,似乎Business类缺少一些列。我确保使用PFQuery的include键,以便Business类返回它的所有属性,但它似乎包含的唯一属性是它的对象ID。

(lldb) po businesses <__NSArrayM 0x174050b60>( <Business: 0x170118810, objectId: 7Sdh8a0d8, localId: (null)> { } )

抱歉,我已经包含了这么多代码,我觉得我的错误可能在任何地方。为什么我的查询不返回完整的Business对象?

谢谢!

1 个答案:

答案 0 :(得分:1)

啊,我是个傻瓜。这一切都在

[Business parseClassName]

我要求关键的“商业”而不是“商业”