[英]newbie IOS 5: How do I get Facebook to return “About Me” data on the currently logged in user?
[英]How do I create an inverse relationship for a User when I'm only allowed to save the currently logged in user?
我的User類與Convos類有多對多的關系。 我想將user
(這是一個不是當前登錄用戶的PFUser *
)添加到convo
對象,我想將convo
添加到user
對象以獲得反向關系。
PFRelation *relation = [self.convo relationforKey:@"users"];
[relation addObject:user];
[self.convo save];
PFRelation *inverseRelation = [user relationforKey:@"convos"];
[inverseRelation addObject:self.convo];
[user save];
問題是我不允許保存user
因為顯然我只能保存當前登錄的用戶。 這是錯誤:
除非已通過logIn或signUp對用戶進行身份驗證,否則無法保存用戶
我該如何解決這個問題?
我能想到的最簡單方法是擁有一個擁有Convos關系的獨立PFObject。 例如
PFUser["proxy"] -> PFObject["convos"] -> PFRelation
您的代碼將變為:
PFObject *relation = [self.convo relationforKey:@"users"];
[relation addObject:user];
PFObject *userProxy = [user objectForKey:@"proxy"];
// N.B. You need to make sure this object exists already, and create it if not
// N.B. Make sure you include this key when you query for the user, or you'll need to load the data here
if (userProxy == nil) NSAssert(nil, @"Need to create the users Proxy object");
if (userProxy.isDataAvailable == NO) NSAssert(nil, @"Need to include the Proxy object key in the user query");
PFRelation *inverseRelation = [userProxy relationforKey:@"convos"];
[inverseRelation addObject:self.convo];
[PFObject saveObjects:@[self.convo, userProxy]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.