2009-09-30 93 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