Details
Description
When building models and database structure from YAML schema, Doctrine ignores the behaviors and relations on models if it is named "User":
...
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
...
This creates the following table structure:
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;
The table structure is both missing foreign key constraints to Company, Timezone and Role. It is also missing columns updated_at and created_at for Timestampable behavior. The slug column for Sluggable behavior is missing, as well.
When looking at the BaseUser::setUp() method it looks as it is supposed to:
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);
}
....
}
So the only area where it goes wrong, is when generating the queries for creating the model tables. I don't know if the same problem appears with other model names, but it doesn't like models named "User".
If I rename the model to "Person" and rebuild, it all works perfectly as it should.
Activity
| Field | Original Value | New Value |
|---|---|---|
| Description |
When building models and database structure from YAML schema, Doctrine ignores the behaviors and relations on models if it is named "User": {code:none} ... 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 ... {code} This creates the following table structure: {code:sql} 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; {code} The table structure is both missing foreign key constraints to Company, Timezone and Role. It is also missing columns {{updated_at}} and {{created_at}} for Timestampable behavior. The {{slug}} column for Sluggable behavior is missing, as well. When looking at the BaseUser::setUp() method it looks as it is supposed to: {code:none} 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); } .... } {code} So the only area where it goes wrong, is when generating the queries for creating the model tables. I don't know if the same problem appears with other model names, but it doesn't like models named "User". |
When building models and database structure from YAML schema, Doctrine ignores the behaviors and relations on models if it is named "User": {code:none} ... 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 ... {code} This creates the following table structure: {code:sql} 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; {code} The table structure is both missing foreign key constraints to Company, Timezone and Role. It is also missing columns {{updated_at}} and {{created_at}} for Timestampable behavior. The {{slug}} column for Sluggable behavior is missing, as well. When looking at the BaseUser::setUp() method it looks as it is supposed to: {code:none} 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); } .... } {code} So the only area where it goes wrong, is when generating the queries for creating the model tables. I don't know if the same problem appears with other model names, but it doesn't like models named "User". If I rename the model to "Person" and rebuild, it all works perfectly as it should. |