Symfony / Doctrine中的模式

时间:2010-10-03 21:27:01

标签: php

# config/doctrine/schema.yml
Category:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true, unique: true }

Project:
  actAs: { Timestampable: ~ }
  columns:
    category_id:  { type: integer, notnull: true }
    title:         { type: string(255) }
    description:  { type: string(4000), notnull: true }
  relations:
    Category: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: Projects }

在这里,

如果我们改变

local:category_id'到'foreign_key:category_id

foreign:id'到'references:id

然后它会更有意义还是原来的呢?

我的意思是Symfony的创造者真的很有经验[Jonathan Wage和Fabien Potencier]所以他们必须遵循我可能不知道的一些数据库设计。

只是好奇才知道如果有人知道它为什么,它在Symfony中的方式?

1 个答案:

答案 0 :(得分:1)

令人遗憾的是,文档很广泛,同时在非常基础的部分(例如数据库模式)中很少。

AFAIK,我们对给定的关系有以下结构:

"Alias":        #Name of the set of records in the other table, referenced from this table
  foreignAlias:   #Name of the set of records in this table, referenced from the other table
  type:           #multiplicity of the records in the other table; can be "one" or "many"
  foreignType:    #multiplicity of the records in this table; can be "one" or "many"
  local:          #field of this table that references records of the other table
                  #for a many to many relation, field of the middle table that references records of this table
  class:          #class of the other table; identifies referenced records
  foreign:        #field of the other table; identifies referenced records
                  #for a many to many relation, field of the middle table that references records of the other table
  refClass:       #for a many to many relation, class of the middle table
  onDelete:       #database level referential integrity, only on the table that owns the foreign key
  onUpdate:       #database level referential integrity, only on the table that owns the foreign key
  cascade:        #application level cascade
  foreignKeyName: #name of the constraint for the foreign key
IMO,可以更简单,更直观。