Doctrine 1
  1. Doctrine 1
  2. DC-362

Doctrine fails to create correct table structure if model is named "User"

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.0-RC1
    • Fix Version/s: None
    • Component/s: Behaviors, Query, Relations
    • Labels:
      None
    • Environment:
      Mac OS X 10.6.2 (10C540) (Snow Leopard) with MAMP 1.8 bundle:
      PHP Version: 5.2.10,
      MySQL Version: 5.1.37

      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

        Michael Henriksen created issue -
        Michael Henriksen made changes -
        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.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Michael Henriksen
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: