我有一堆数组中的PFFetch对象。那些对象具有到其他对象的链接(指针数组< - >指针)。要限制为我的初始提取发送的数据量,我不想在提取时使用includeKey下载所有链接对象。
稍后,我有这些对象的子集,我确实想要获取这些对象的相关对象和关系。如果我再次获取它们,我会复制我的应用程序中的对象(并且可能不必要地通过我已经在我的应用程序中的线路发送对象)
即。我希望我的原始数组中的一些对象看起来好像原始fetch有:
[query includeKey:@"relationship"];
[query includeKey@"relationship.secondRelationship"];
设置原始密钥。做这个的最好方式是什么?我曾在PFObject上想象过一些API,如:
+(void) fetchIfNeededInBackground:(NSArray*)objects includeKey:(NSString*)key block:...
或
- (void)includeKeyAtNextFetch:(NSString*)key
但是我找不到这样的东西。
答案 0 :(得分:2)
您可能会在着名的 containsIn 查询后继续...
这里有一个使用containsIn来解决这个着名问题的例子"匹配来自FB&#34的朋友...... ....
+(void)findFBFriendsWhoAreOnSkywall
{
// issue a fb graph api request to get the fbFriend list...
[APP huddie];
[FBRequestConnection
startForMyFriendsWithCompletionHandler:^(
FBRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
// here, the result will contain an array of the user's
// FB friends, with, the facebook-id in the "data" key
NSArray *fbfriendObjects = [result objectForKey:@"data"];
int kountFBFriends = fbfriendObjects.count;
NSLog(@"myfriends result; count: %d", kountFBFriends);
// NOW MAKE A SIMPLE ARRAY of the fbId of the friends
// NOW MAKE A SIMPLE ARRAY of the fbId of the friends
// NOW MAKE A SIMPLE ARRAY of the fbId of the friends
NSMutableArray *fbfriendIds =
[NSMutableArray arrayWithCapacity:kountFBFriends];
for (NSDictionary *onFBFriendObject in fbfriendObjects)
[fbfriendIds addObject:[onFBFriendObject objectForKey:@"id"]];
for (NSString *onef in fbfriendIds)
NSLog(@"and here they are .. %@", onef);
// query to find friends whose facebook ids are in that list:
// USE THAT SIMPLE ARRAY WITH THE MAGIC 'containedIn' call...
// amazingly easy using the ever-loved containedIn:
// amazingly easy using the ever-loved containedIn:
// amazingly easy using the ever-loved containedIn:
PFQuery *SWUSERSTOADDASFRIENDS = [PFUser query];
[SWUSERSTOADDASFRIENDS whereKey:@"fbId" containedIn:fbfriendIds];
[SWUSERSTOADDASFRIENDS findObjectsInBackgroundWithBlock:^
(NSArray *objects, NSError *error)
{
if (error) // problem getting the matching-friends list
{
[PFAnalytics .. it al went to hell.];
NSLog(@"disaster at the last step! but that's ok");
[APP.hud hide:YES];
[backTo literallyGoToMainPage];
}
else
{
// so all the people in OBJECTS, now make them in to SW friends.
[PFAnalytics trackEvent:@"FBMatchDone" ...];
NSLog(@"found this many fb matches ... %d", objects.count);
[FBMatch actuallyMakeThemFriends:objects];
[APP.hud hide:YES];
[FBMatch message .. objects.count showTheseNames:objects];
}
}];
}
else // problem getting the friend list....
{
[PFAnalytics .. problem];
[APP.hud hide:YES];
[backTo literallyGoToMainPage];
}
}];
}
我希望它有所帮助!