2009-09-30 99 views
2

我有一個AccountCredential對象,其中包含標準的用戶憑證,然後另一個對象包含這些AccountCredential對象中的幾個。當我在CoreData中對這個模型進行建模時,我想知道AccountCredential是否需要將它關係鏈接回Account以獲取它所擁有的每個實例。核心數據建模關係審查

會我把它架在CoreData就象這樣:

@interface Account : NSManagedObject 
{ 
} 

@property (nonatomic, retain) AccountCredential * twitterAccountCred; 
@property (nonatomic, retain) AccountCredential * facebookAccountCred; 

@end 


@interface AccountCredential : NSManagedObject 
{ 
} 

@property (nonatomic, retain) NSString * password; 
@property (nonatomic, retain) NSString * username; // encrypted 
@property (nonatomic, retain) Account * account1; 
@property (nonatomic, retain) Account * account2; 

@end 

或者是足夠足夠的帳戶必須AccountCredential參考和AccountCredential沒有關係鏈接帳戶?

AccountCredential沒有理由知道它被用於'賬戶'界面中的兩種類型的賬戶,所以我把它看作是一個單向的參考。我明白CoreData喜歡關係是雙向的,但我很好奇這是否在模型中是必要的。

非CoreData的關係是這樣的:

@interface AccountCredential : NSObject { 
    NSString *username; 
    NSString *password; //encrypted 
} 
@end 

@interface Account : NSObject { 
    AccountCredential  *twitterAccountCred; 
    AccountCredential  *facebookAccountCred; 
} 
@end 

回答

0

如果建立這個時,Xcode將有可能給你的警告,有沒有反向的關係。當你有相反的關係時,CoreData真的很喜歡它(我不記得推理,但是當你真的考慮它時它確實有意義)。

+0

核心數據使用反向關係信息來確保對象圖的一致性,如果發生更改。但我想知道如果我不需要做相反的關係......如果是的話,是否還有辦法抑制這種警告? – 2009-09-30 17:19:40