与指针没有获取数据的pfuser
我已经分类了PFuser并注册了它。 它效果很好。
在我的数据库的用户表中,我做了一个指向另一个表,有更多的信息。
该应用程序不断崩溃,这个错误:
2014-06-08 15:14:59.550 App[2333:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "place" has no data. Call fetchIfNeeded before getting its value.'
当检查debugging器,我可以看到它使连接到另一个表,但所有的领域都是空的。
我想我需要把这样的东西: [query includeKey:@"company"];
为指针,但我不做一个用户类的查询…
我需要覆盖它的地方?
这是我的自定义用户类:
-h文件
#import "Company.h" @interface PFCustomUser : PFUser<PFSubclassing> @property (nonatomic, retain) NSString *name; @property (nonatomic, retain) UIImage *userPhoto; @property (nonatomic, retain) Company *company; + (PFCustomUser *)currentUser;
-m文件
#import "PFCustomUser.h" @implementation PFCustomUser @dynamic name,userPhoto,company; + (PFCustomUser *)currentUser { return (PFCustomUser *)[PFUser currentUser]; }
在appdelegate我这样做
[PFCustomUser registerSubclass];
所以技术上我会做一个控制器
PFCustomUser *currentUser = [PFCustomUser currentUser]; NSLog(@"%@",currentUser.company.place);
公司是这样,所以地方是n。 因此错误..在debugging器中,你可以看到它看到公司的objectId和类名,但其余的是没有
你必须为每个指针或关系添加一个setter和getter。
.h文件
@property (retain) PFRelation *likes;
.m文件
@synthesize likes = _likes; - (void) setLikes:(PFRelation *)likes{ _likes = likes; } - (PFRelation *) likes{ if(_likes== nil) { _likes = [self relationforKey:@"likes"]; } return _likes; }
示例代码:
PFPlace *place = [PFPlace object]; place.name = @"Taiwan"; [person save]; [place save]; [place.likes addObject:person] [place save];
https://www.parse.com/questions/pfobject-subclassing-with-pfrelation-as-attribute