2010-04-13 56 views

回答

0

您可以使用YAML製作DB的設計。如果你想使你需要做的是這樣的一個NM關係(它顯示有關一個以上的所有者狗和業主更比狗傻瓜例子)

--- 
options: 
    type: INNODB 
    collate: utf8_unicode_ci 
    charset: utf8 

Human: 
    columns: 
     id: 
      type: integer(4) 
      primary: true 
      autoincrement: true 
     name: 
      type: varchar(64) 
      notnull: true 
     ... 
     ... 
    relations: 
     Dogs: 
      foreignAlias: Humans 
      class: Dog 
      ref_class: Human_Dogs 
Dog: 
    columns: 
     id: 
      type: integer(4) 
      autoincrement: true 
      primary: true 
     owner: 
      type: varchar(64) 
      notnull: true 
     ... 
     ... 
    relations: 
     Humans: 
      foreignAlias: Dogs 
      class: Human 
      ref_class: Human_Dogs 
Human_Dogs: 
    columns: 
     human_id: 
      type: int(4) 
      primary: true 
     dog_id: 
      type: int(4) 
      primary: true 
    relations: 
     Human: 
      foreignAlias: Human_Dogs 
     Dog: 
      foreignAlias: Human_Dogs 

這將是該文件.yml,所以現在你可以從這個文件生成數據庫。你可以這樣做的方式很大程度上取決於你正在使用的框架或程序。無論如何,這裏有一個簡單的方法可以在PHP + Doctrine中執行:

<?php 
$options = array(
     'packagesPrefix' => 'Plugin', 
     'baseClassName' => 'MyDoctrineRecord', 
     'suffix'   => '.php' 
); 

Doctrine_Core::generateModelsFromYaml('/path/to/file.yml', '/path/to/model', $options); 
?> 

通過正確的配置,您可以自動生成id字段。

在這個環節有一個教程 - >Documentation

我希望這可以幫助你!

+0

(在鏈接中,您將看到另一種方式來執行多對多關係,選擇一個您喜歡的方式,都可以) – 2010-04-14 21:29:58

+0

我也有同樣的問題。但然後我必須從yaml創建模型,並且不能使用工作臺來首先創建表格,然後將它們導入到yaml中? – 2010-04-21 23:34:49