2010-10-03 61 views
0
# 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 } 

這裏,架構中的Symfony /原則

如果我們改變

地方:CATEGORY_ID '到' foreign_key:CATEGORY_ID

國外:ID '到' 引用:編號

那麼它會更有意義或原始人呢?

我的意思是Symfony的創造者們真的很有經驗[Jonathan Wage和Fabien Potencier],所以他們必須遵循我不知道的一些數據庫設計。

只是好奇知道如果有人知道它爲什麼,這是在Symfony的方式?

回答

1

非常可惜的是,文檔是非常廣泛的,同時在非常基本的部分(如數據庫模式)中也很少見。

據我所知,我們有一個給定的關係結構如下:

"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,可能是更簡單,更直觀。