gpt4 book ai didi

ios - 如果删除 PFUser,则以编程方式删除与 PFUser.objectID 关联的数据

转载 作者:搜寻专家 更新时间:2023-11-01 07:27:57 28 4
gpt4 key购买 nike

所以在我的应用程序中,我对用户帐户使用 Parse。我有一个“关注”类,其中包含包含用户对象 ID 的“至”和“来自”字段,允许用户相互关注。现在,如果我以某种方式删除用户,跟随关系将保持不变,并且查询空用户数据会引发未找到对象错误。我想知道的是,如果任何“到”或“来自”字段包含不存在的对象的 objectID,我如何删除跟随关系。

我曾尝试通过对象 ID 查询对象,但任何检查空数据的尝试(例如检查 user.username 是否为 nil)都会导致对象丢失错误,而且我无法检查对象是否为 nil,因为Xcode 说它永远不会。

谢谢!

最佳答案

我认为你需要手动获取它,如果你删除了用户,那么你可以删除它的所有关系以维护数据库的完整性,下面是你删除任何用户后调用的代码。

PFQuery * _to = [PFQuery queryWithClassName:@"Follow"];
[_to whereKey:@"to" equalTo:@"Replace UserID of Deleted User"];

PFQuery * _from = [PFQuery queryWithClassName:@"Follow"];
[_from whereKey:@"from" equalTo:@"Replace UserID of Deleted User"];

PFQuery *query = [PFQuery orQueryWithSubqueries:@[_to, _from]];
[query findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d relations.", results.count);
// Do something with the found objects, lets delete them all to intact relationship
[PFObject deleteAllInBackground:results];
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];

请点击此链接获取详细说明和信息:
Parse Compound Queries

关于ios - 如果删除 PFUser,则以编程方式删除与 PFUser.objectID 关联的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34669698/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com