我有两门课:
@interface RMEvent : PFObject <PFSubclassing>
@property (nonatomic, strong) NSArray *attachments;和
@interface RMFile : PFObject <PFSubclassing>
@property (nonatomic, strong) PFObject *event;我要这么做:
RMEvent *newEvent = [RMEvent object];
[newEvent pinInBackground];
RMFile *newFile = [RMFile object];
newFile.event = newEvent;
[newFile pinInBackground];
[newEvent addObject:newFile forKey:@"attachments"];我可以看到对象是在本地创建的(通过对localDatabase的查询进行测试)。一切看起来都还好。但是我做了(在很多不同的组合中):
[newEvent saveEventually];
[newFile saveEventually];我在服务器上什么也看不见。如何将这些对象保存到服务器?什么是正确的顺序,还是我做错了什么?
P.S.:我在每个子类‘+load方法中都有自registerSubclass,并且在RMEvent的+object方法中实例化一个数组,所以不应该是这样的。
发布于 2015-06-11 15:05:27
您应该检查saveEventually回调是否出错。
[newFile saveEventually:^(BOOL success, NSError *error) {
if (error) NSLog(error);
}];RMFile是PFFile子类吗?如果是这样,则不能saveEventually一个PFFile,也不能保存一个对象,该对象作为指向未保存的新PFfile的指针
编辑:“在保存时找到一个循环依赖项”
没有云代码:
RMEvent *newEvent = [RMEvent object];
RMFile * newFile = [RMFile object];
newEvent[@"newFile"] = newFile;
[newEvent saveInBackgroundWithBlock:^(BOOL success, NSError *error)
{
if(!error)
{
newFile[@"newEvent"] = newEvent;
[newFile saveEventually];
}
}];使用CloudCode:
RMEvent *newEvent = [RMEvent object];
RMFile * newFile = [RMFile object];
newEvent[@"newFile"] = newFile;
[newEvent saveInBackground];然后在CloudCode afterSave触发器上,您可以检索您的RMEvent,从中获取' newFile‘键,在newFile对象上指定一个指向newEvent的指针,然后保存newFile
https://stackoverflow.com/questions/30784478
复制相似问题