开发者

Seeking Core Data model design advice

I have the following modeling problem in Core Data. A Student can take Lessons. A Lesson has the following fields:

title
date
grade
type

A Lesson can be one of three types:

lessontype1:

subtype11 subtype12 subtype13

lessontype2:

subtype21 subtype22 subtype23 su开发者_运维技巧btype24

lessontype3:

 subtype31 subtype32 subtype33 subtype34 subtype35

How do I set the lesson.type to any of these three types of Lessons? Is there a better way to model this scenario?


The details of your model depend on details of the data you are modeling.

If the types are just markers that have no logic or behavior associated with them, then the simplest model would be:

Student{
    lessons<-->>Lesson.student
}

Lesson{
    title:string
    date:date
    grade:number
    type:string
    subtype:string
    student<<-->Student.lessons
}

If the lessons have some kind of behavior associated with each type, then you could create subentities for each type of lesson.

Lesson{
    title:string
    date:date
    grade:number
    student<<-->Student.lessons
}

TypeOne:Lesson{

}

TypeOneSubOne:TypeOne{

}

// ...etc

Since all the Lesson subentities inherit from Lesson, they can inherit the relationship as well. All the different subentities can be in the Student.lesson relationship.

If the types of lessons have behaviors associated with them, you can break them out into separate entities as well.

Lesson{
    title:string
    date:date
    grade:number
    type<<-->Type.lessons
    student<<-->Student.lessons
}

Type{
    lessons<-->>Lesson.type
}

TypeOne:Type{

}

TypeOneSubOne:TypeOne{

}

A Core Data model is intended to simulate real-world objects, events or conditions and the relationships between them. The first step in designing a model is to understand those real-world things and the relationships between them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜