[DC-362] Doctrine fails to create correct table structure if model is named "User" Created: 16/Dec/09 Updated: 08/Jan/10 |
|
| Status: | Open |
| Project: | Doctrine 1 |
| Component/s: | Behaviors, Query, Relations |
| Affects Version/s: | 1.2.0-RC1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Michael Henriksen | Assignee: | Jonathan H. Wage |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Environment: |
Mac OS X 10.6.2 (10C540) (Snow Leopard) with MAMP 1.8 bundle: |
||
| 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. |
| Comments |
| Comment by Michael Henriksen [ 16/Dec/09 ] |
|
Forgot to mention, that it works perfectly when renaming model to something else than "User" |
| Comment by Sander [ 08/Jan/10 ] |
|
Have the same problem in 1.2.1 at PostgreSQL 8.4 |