Doctrine を ORM として使用しているプロジェクトの 1 つに問題があります。
何らかの理由で、モデルとデータベース構造を再構築するとき、Doctrine はテーブル定義の 1 つで定義したビヘイビアとリレーションを無視します。YAML テーブル定義は次のようになります。
...
User:
actAs:
Timestampable:
Sluggable:
unique: true
fields: username
canUpdate: true
columns:
id:
type: integer(4)
primary: true
autoincrement: true
company_id
type: integer(4)
timezone_id:
type: integer(1)
role_id:
type: integer(1)
email:
type: string(255)
username:
type: string(255)
unique: true
password:
type: string(40)
firstname:
type: string(255)
lastname:
type: string(255)
last_login:
type: datetime
relations:
Company:
local: company_id
foreign: id
Timezone:
local: timezone_id
foreign: id
Role:
local: role_id
foreign: id
...
生成されたテーブル構造は次のようになります。
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT NULL,
`timezone_id` tinyint(4) DEFAULT NULL,
`role_id` tinyint(4) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
`password` varchar(40) DEFAULT NULL,
`firstname` varchar(255) DEFAULT NULL,
`lastname` varchar(255) DEFAULT NULL,
`last_login` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ご覧のとおり、Doctrine は私が定義したすべての列を生成しますが、何らかの理由で、自動的に行われるはずのすべての処理が行われていません。まず、Timestampable 動作の列updated_at
と列が作成されず、Sluggable 動作の列も欠落しています。created_at
slug
インデックスと外部キー制約も欠落しています。
生成されたモデル クラスを開くと、問題ないように見えます。
class BaseUser extends Doctrine_Record
{
....
public function setUp()
{
parent::setUp();
$this->hasOne('Company', array(
'local' => 'company_id',
'foreign' => 'id'));
$this->hasOne('Timezone', array(
'local' => 'timezone_id',
'foreign' => 'id'));
$this->hasOne('Role', array(
'local' => 'role_id',
'foreign' => 'id'));
$timestampable0 = new Doctrine_Template_Timestampable();
$sluggable0 = new Doctrine_Template_Sluggable(array(
'unique' => true,
'fields' => 'username',
'canUpdate' => true,
));
$this->actAs($timestampable0);
$this->actAs($sluggable0);
}
....
}
したがって、問題は SQL クエリの生成にあります...
他の誰かが同様の問題を経験したことがありますか、それとも私の YAML 定義のエラーを見つけることができますか?