since: 2011/08/27
update: 2011/08/29
A. 說明:
1. Core Data manages an object graph using real object references. It has no need
for a unique autoincrement identifier that can be used as a primary key in the
same sense it would be used in a relational database.
備註: a. 譯: Core Data 使用真實的物件參照來管理物件圖表, 因此不需要像
關聯式資料庫那樣使用自動新增的獨一無二 ID 來當主鍵.
b. Core Data is not a database; it's an object graph persistence framework.
2. All Core Data attributes must have a class type.
ex: Entity: Organization
Attribute: id (with type: Integer 16)
// a. create a primitive int from the hash of the organization object
NSManagedObject *organization = ....;
int orgID = [organization hash];
// b. convert the primitive int into an NSNumber object,
// which can be used in the setValue:forKey: method.
[organization setValue:[NSNumber numberWithInt:orgID] forKey:@"id"];
3. Core Data returns the "many" side of a one-to-many relationship as a set(NSSet).
ex: add some employees to the relationship
NSManagedObject *john = ....;
NSManagedObject *jane = ....;
NSManagedObject *bill = ....;
NSMutableSet *johnsEmployees = [john mutableSetValueForKey:@"employees"];
[johnsEmployees addObject:jane];
[johnsEmployees addObject:bill];
B. 資料模型規劃:
Entity:
NoteBook ----> 筆記本
Attributes:
name (type: string) ----> 筆記本名稱(必要)
subName (type: string) ----> 筆記本副名稱(非必要)
articleCount (type: int 16) ----> 文章數量(必要, 預設值:0)
type (type: int 16) ----> 種類(系統預設的, 使用者新增的), (必要, 預設值:0)
dateCreated (type: Date) ----> 建立日期 (非必要)
dateUpdate (type: Date) ----> 更新日期 (非必要)
status (type: int 16) ----> 筆記本狀態 (正常, 刪除), (必要, 預設值:1)
flag (type: int 16) ----> 備用旗標, (非必要, 預設值:0)
---------------------------------------------------------------------------------------------------------------
Entity:
NoteArticle ----> 筆記文章
Attributes:
title (type: string) ----> 英文標題(或使用者新增的) (必要, indexed)
titleC (type: string) ----> 中文標題 (非必要, indexed)
subTitle (type: string) ----> 副標題 (非必要)
content (type: string) ----> 英文內容(或使用者新增的) (必要)
contentC (type: string) ----> 中文內容 (非必要)
readCount (type: int 16) ----> 文章讀取次數, (必要, 預設值:0)
favorite (type: Boolean) ----> 是否為我的最愛, (必要, 預設值:NO)
type (type: int 16) ----> 文章種類(系統預設的, 使用者新增的), (必要, 預設值:0)
version (type: string) ----> 適用的版本 (非必要)
memo (type: string) ----> 備註攔 (非必要)
dateCreated (type: Date) ----> 建立日期 (非必要)
dateUpdate (type: Date) ----> 更新日期 (非必要)
status (type: int 16) ----> 文章狀態 (正常, 刪除), (必要, 預設值:1)
flag (type: int 16) ----> 備用旗標, (非必要, 預設值:0)
---------------------------------------------------------------------------------------------------------------
Relationship:
from: NoteBook
Name: articles
Destination: NoteArticle
Properties: Optional
Plural: To-Many Relationship (一對多)
Delete Rule: Cascade (瀑布似地)
---------------------------------------------------------------------------------------------------------------
Relationship:
from: NoteArticle
Name: book
Destination: NoteBook
Inverse: articles
Properties: Optional
Delete Rule: Nullify (廢棄)
C. 建立完成:
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。