[英]Schema in Symfony/Doctrine
# 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 }
这里,
如果我们改变
本地:category_id'到'外键:category_id
和
国外:ID“至”参考:ID
那么它会更有意义,还是原始版本呢?
我的意思是Symfony的创建者真的很有经验[Jonathan Wage和Fabien Potencier],所以他们必须遵循一些我可能不知道的DB Design。
只是想知道如果有人知道为什么会这样,Symfony的方式呢?
遗憾的是,该文档非常丰富,同时又很少包含非常基本的部分,例如数据库架构。
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,可能会更简单,更直观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.