I have an AccountCredential object which holds standard user credentials and then another object that holds several of these AccountCredential objects. When I model this in CoreData, I'd like to know if AccountCredential needs to have a relationship link back to Account for every instance it holds.
Would I set it up in CoreData as this:
@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
Or is it sufficient enough for Account to have a reference to AccountCredential and no relationship link from AccountCredential to Account?
There's no reason for AccountCredential to know that it is used for two types of accounts in the 'Accounts' interface so I see it as a uni-directional reference. I understand that CoreData likes relationships to be bidirectional but I'm curious as to if this is necessary in the model or not.
A non-CoreData relationship would look like this:
@interface AccountCredential : NSObject {
NSString *username;
NSString *password; //encrypted
}
@end
@interface Account : NSObject {
AccountCredential *twitterAccountCred;
AccountCredential *facebookAccountCred;
}
@end