0

generateModelsFromDbを使用してモデルを生成する場合、Doctrineは、ベーステーブル自体の間にnm関係を生成する代わりに、リレーションテーブルとベーステーブルの間に1対多のリレーションを作成します。generateModelsFromDbにnm関係を検出させる方法はありますか?

4

1 に答える 1

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

これがfile.ymlになるので、このファイルからDBを生成できます。それを行う方法は、使用しているフレームワークまたはプログラムに大きく依存します。とにかくここにPHP+Doctrineでそれを行う簡単な方法があります:

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

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

適切な構成を使用すると、idフィールドを自動生成できます。

このリンクにはチュートリアル->ドキュメントがあります

これがお役に立てば幸いです。

于 2010-04-14T21:27:27.583 に答える