【问题标题】:Properties of relations in Core DataCore Data 中关系的属性
【发布时间】:2010-12-19 02:09:38
【问题描述】:

为了更好地学习 Cocoa 和 Core Data,我决定构建一个包含烹饪食谱的应用程序。但是,在尝试创建 CD 模型时,我已经卡住了。

这是三个简化的类:

Recipe:
name
ingredients
instructions

Ingredient:
name
unit (liter, teaspoon etc)

当然,Recipe 中的成分关系也需要跟踪所需的量。如果我要立即构建一个 SQL 表,我会得到:

Recipe:  Ingredient:  Recipe_Ingredient:
id       id           recipe_id
name     name         ingredient_id
instr    unit         amount

究竟如何才能将此Recipe_Ingredient 关系放入CD 模型中?我是否只需添加一个包含这些属性的RecipeIngredients 实体?

【问题讨论】:

    标签: objective-c cocoa core-data


    【解决方案1】:

    是的,如果您想将属性添加到关系中,您需要使用中间实体将配方和成分实体连接在一起并添加数量属性。

    如果您是 Core Data 的新手,您可能还会发现以下两个链接很有用:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多