[英]question about relationship in coredata iphone
我正在使用iPhone中的核心數據,似乎一切正常(創建數據庫並保存一些數據),直到我發現一些我還沒有得到的東西
我有3個實體(員工,天,中心),其中一個與其他兩個有一對多的關系,
ENTITY RELATIONSHIP ENTITY Employee>>>>days(one to many)>>Days (inverse of Days, employee) Employee>>>>centre(one 2 many)>Centre (inverse of Centre, employee)
在我的sqlite生成的數據庫中,我使用sqlite管理器(firefox)進行了檢查,並且在(Z_PK,Z_ENT,Z_OPT,ZEMPLOYEE)之后顯示了一個實體(ZCENTRE)的關系,但未按該順序顯示(這是預期的命令?對於我的其他實體(Z_DAYS),它顯示在屬性之后,所以讓我認為代碼中的實體不是屬性,而是?
在模型的代碼中,對於center.h
#import <CoreData/CoreData.h>
@class Employee;
@interface Centre : NSManagedObject
{}
@property (nonatomic, retain) NSString * centres;
@property (nonatomic, retain) Employee * employee;
@end
和模型中心
#import "Centre.h"
#import "Employee.h"
@implementation Centre
@dynamic centres;
@dynamic employee;
@end
這是可行的,並且Days.h和Days.m的代碼完全相同,但當然會改變屬性,
我必須在模型中調用它們嗎? (我認同!)
for the Employee.h>>>@class Centre;
@class Days;
@property (nonatomic, retain) Centre * centre;
@property (nonatomic, retain) Days * days;
為了員工
#import "Employee.h"
#import "Centre.h"
#import "Days.h"
@implementation Employee
@dynamic centre;
@dynamic days;
好,多謝!
需要考慮的一些事情:
NSManagedObject
子NSManagedObject
? 如果您不需要自定義行為,則無需將它們創建為單獨的類。 如果確實需要,那么實體可以使用上述模型中設置的那些類嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.