actAs和关系在学说中意味着什么?

时间:2010-02-18 12:45:39

标签: php doctrine

我完全不知道以下schema.yml:

JobeetCategory:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true, unique: true }

JobeetJob:
  actAs: { Timestampable: ~ }
  columns:
    category_id:  { type: integer, notnull: true }
    type:         { type: string(255) }
    company:      { type: string(255), notnull: true }
    logo:         { type: string(255) }
    url:          { type: string(255) }
    position:     { type: string(255), notnull: true }
    location:     { type: string(255), notnull: true }
    description:  { type: string(4000), notnull: true }
    how_to_apply: { type: string(4000), notnull: true }
    token:        { type: string(255), notnull: true, unique: true }
    is_public:    { type: boolean, notnull: true, default: 1 }
    is_activated: { type: boolean, notnull: true, default: 0 }
    email:        { type: string(255), notnull: true }
    expires_at:   { type: timestamp, notnull: true }
  relations:
    JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs } 

JobeetAffiliate:
  actAs: { Timestampable: ~ }
  columns:
    url:       { type: string(255), notnull: true }
    email:     { type: string(255), notnull: true, unique: true }
    token:     { type: string(255), notnull: true }
    is_active: { type: boolean, notnull: true, default: 0 }
  relations:
    JobeetCategories:
      class: JobeetCategory
      refClass: JobeetCategoryAffiliate
      local: affiliate_id
      foreign: category_id
      foreignAlias: JobeetAffiliates

JobeetCategoryAffiliate:
  columns:
    category_id:  { type: integer, primary: true }
    affiliate_id: { type: integer, primary: true }
  relations:
    JobeetCategory:  { onDelete: CASCADE, local: category_id, foreign: id }
    JobeetAffiliate: { onDelete: CASCADE, local: affiliate_id, foreign: id }

如何正确定义?

1 个答案:

答案 0 :(得分:4)

短而甜蜜:

行为('actAs')顾名思义,是一种定义模型行为(sp-sorry,英国;-))的方法。我说最常用的是“Timestampable”(它将创建和更新的字段添加到您的表中并自动更新)和“SoftDelete”(添加了一个deleted_at列,如果记录被“删除”,则加上时间戳,而不是实际的删除记录)。

此处有更多信息 - http://www.doctrine-project.org/documentation/manual/1_2/en/behaviors

关系 - 将模型与其他模型相关联。例如,博客文章可能有很多评论 - 帖子和评论之间的一对多关系。在上面的Jobeet示例中,Job属于Category。

再次提供更多信息 - http://www.doctrine-project.org/documentation/manual/1_2/en/defining-models#relationships

但是,正如@Marko在上面评论的那样,从文档开始:-)来自Symfony文档的page,你已经得到了架构甚至有一张图片来解释表格之间的关系...... : - )