Doctrine ORM コマンド メモ
追記(2013/1/26)
#composer.json { "require": { "phpunit/phpunit": "3.7.*", "doctrine/orm": "*" } }
上記のcomposer.jsonを用意して「./composer.phar install」を実行してvendorディレクトリがつくられるとき、vendorディレクトリの中にbinディレクトリがあって、composerでインストールしたもので、コマンドから実行する系のものはbinディレクトリに入っている。
以下は上記の「composer.json」を「./composer install」したとき、vendor/binディレクトリに作られるファイル一覧
#/path/to/vendor (include 「bin」directory) $ tree bin/ bin/ ├── doctrine -> ../doctrine/orm/bin/doctrine ├── doctrine.php -> ../doctrine/orm/bin/doctrine.php └── phpunit -> ../phpunit/phpunit/composer/bin/phpunit
前回このページの「25.1.3. Configuration (Non-PEAR)」からdoctrineコマンドを実行させるためのphpファイルをつくっていたがわざわざそんな事しなくても良かったみたい。
前準備
今回composerを使ってインストールしているからこのページの「25.1.3. Configuration (Non-PEAR)」を見てdoctrineのコマンドを使えるようにする
基本的にわからなくなったらhelp
以下のように「doctrine」コマンド(ここではphp doctrine.php)とorm:○○の間にhelpを入れればorm:○○の使い方の詳細が見れるからとりあえずまずはhelpを使って使い方を確認。
php doctrine.php help orm:generate-entities
既にあるDBからORMの設定ファイル(yaml形式)と関連するエンティティ(各DBのオブジェクト)クラスを生成
php doctrine.php orm:convert-mapping --namespace="Entities\" --from-database yml /path/to/config_yaml_dir
php doctrine.php orm:generate-entities /path/to/entitities_dir
php doctrine.php orm:validate-schema
気になったところ
- TinyIntはbooleanとして認識されるっぽい
- しかも2以上いれても全て1になる(0か1だけしか値が入らないようにマッピングされている?)
- フィールドに
read
が入っているとバグが発生する(readが原因じゃないかもしれないが、read_flag
とフィールド名を変更したところ直った)
指定できる型一覧
- string: Type that maps an SQL VARCHAR to a PHP string.
- integer: Type that maps an SQL INT to a PHP integer.
- smallint: Type that maps a database SMALLINT to a PHP integer.
- bigint: Type that maps a database BIGINT to a PHP string.
- boolean: Type that maps an SQL boolean to a PHP boolean.
- decimal: Type that maps an SQL DECIMAL to a PHP string.
- date: Type that maps an SQL DATETIME to a PHP DateTime object.
- time: Type that maps an SQL TIME to a PHP DateTime object.
- datetime: Type that maps an SQL DATETIME/TIMESTAMP to a PHP DateTime object.
- text: Type that maps an SQL CLOB to a PHP string.
- object: Type that maps a SQL CLOB to a PHP object using serialize() and unserialize()
- array: Type that maps a SQL CLOB to a PHP array using serialize() and unserialize()
- float: Type that maps a SQL Float (Double Precision) to a PHP double. IMPORTANT: Works only with locale settings that use decimal points as separator.
http://docs.doctrine-project.org/en/latest/reference/basic-mapping.html
参考URL
- http://stackoverflow.com/questions/7356507/autoload-issue-in-using-doctrine2
- http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html
- http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html#reverse-engineering
- http://stackoverflow.com/questions/13670471/database-fail-the-database-schema-is-not-in-sync-with-the-current-mapping-file