Bunu olmayan bir DBMS açısından CoreData düşünüyoruz. CoreData'da ilişki kurmak için yabancı anahtarları ayarlamanıza gerek yoktur. Bir kullanıcıya bir e-posta atamak istiyorsanız, sadece ikisi arasında bir ilişki oluşturursunuz ve bir kullanıcının "e-posta" özelliğini veya bir e-postanın "kullanıcı" özelliğini ayarlayabilirsiniz. ForeignKey ve bağlantı tüm arka planda CoreData tarafından yapılır.
Başka bir noktada, her ilişki, 1-1, 1- * veya - tanımına dayanmaktadır. Ben
Eğer CoreData ilişkileri oluşturmak
etkili Bu öğe için yeni özelliklerini oluştururken ... başka seçenek emin değilim. Bu biraz açık şeyler yardımcı olur
User *user = [NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:[self.fetchedResultsController managedObjectContext]];
[user setName:@"Matt"];
[user setEmailAddress:@"[email protected]"];
//...Maybe i need to query my institution
NSFetchRequest *query = [[NSFetchRequest alloc] initWithEntityName:@"Institution"];
[bcQuery setPredicate:[NSPredicate predicateWithFormat:@"id == %@", institutionId]];
NSArray *queryResults = [context executeFetchRequest:query error:&error];
[user setInstitution:[queryResults objectForId:0]];
//Now the user adds a email so i create it like the User one, I add the proper
//attributes and to set it to the user i can actually set either end of the
//relationship
Email *email = ...
[email setUser:user];
//Here i set the user to the email so the email is now in the user's set of emails
//I could also go the other way and add the email to the set of user instead.
Hope: olarak bu kadar basittir Ayar
@interface User : NSManagedObject
#pragma mark - Attributes
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *emailAddress;
#pragma mark - Relationships
//All to-many relationships are saved as Sets. You can add to the "emails" relationship attribute to add email objects
@property (nonatomic, strong) NSSet *emails;
//All to-one relationships are saved as types of NSManagedObject or the subclass; in this case "Institution"
@property (nonatomic, strong) Institution *institution;
: İşte bir örnek! CoreData'nın sizin için doğru olduğundan emin olmak için belgelere bakın!
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/CoreData.pdf
ben gerçekten anlamak emin değilim. Bir ilişki 1-M, M-M veya 1-1 değilse o zaman nedir? – paulbailey