CoreData Modeling Relationship Overview
I have an AccountCredential object that contains the standard user credentials, and then another object that contains several of these AccountCredential objects. When I model this in CoreData, I would like to know if the AccountCredential should have an account link reference for each instance it stores.
I would set it to CoreData like 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 enough for an account to have a link to the AccountCredential and a link to the relationship from the AccountCredential to the Account?
There is no reason for AccountCredential to know that it is used for two types of accounts in the Accounts interface, so I am treating it as a one-way link. I understand that CoreData likes the relationship to be bi-directional, but I'm curious if this is needed in the model or not.
A relationship other than CoreData would look like this:
@interface AccountCredential : NSObject {
NSString *username;
NSString *password; //encrypted
}
@end
@interface Account : NSObject {
AccountCredential *twitterAccountCred;
AccountCredential *facebookAccountCred;
}
@end
source to share