Doctrine 1
  1. Doctrine 1
  2. DC-489

Doctrine_Record seems to have a bug with default values when updating

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: Record
    • Labels:
      None
    • Environment:
      PHP 5.2.11

      Description

      So lets see the table:

      User:
      tableName: users
      columns:
      id:
      type: integer(1)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
      username:
      type: string(32)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
      password:
      type: string(48)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
      role:
      type: enum
      fixed: false
      unsigned: false
      values:

      • admin
      • support
        default: support <----- Unable to render embedded object: File (ROOT OF EVIL) not found.
        primary: false
        notnull: true
        autoincrement: false

      So lets say we have a user with `role` = 'support' and want to set em
      'admin' we wrote

      $user = new App_Model_User();
      $user->assignIdentifier(1);
      $user->role = 'admin';
      $user->save();
      var_dump($user->toArray());

      in debugger we see SQL query been made:

      1. [0.55 ms] UPDATE users SET role = ? WHERE id = ?
      • bindings: admin
      • 1

      array(6)

      { ["id"]=> int(1) ["display_name"]=> string(13) "Administrator" ["username"]=> string(4) "root" ["password"]=> string(40) "45bb0f589525a2f0f2a48620bb59b1b8baef0c1d" ["role"]=> string(5) "admin" ["is_active"]=> bool(true) }

      Superb! Works as it should! So lets now set role of this user back to
      'support':

      $user = new App_Model_User();
      $user->assignIdentifier(1);
      $user->role = 'support'; // This value defined as default in scheme,
      thats why have problems
      $user->save();
      var_dump($user->toArray());

      in debugger we didnot see any UPDATE queries! However object is been
      changed, results just has not been flushed to database.

      array(6)

      { ["id"]=> int(1) ["display_name"]=> string(13) "Administrator" ["username"]=> string(4) "root" ["password"]=> string(40) "45bb0f589525a2f0f2a48620bb59b1b8baef0c1d" ["role"]=> string(7) "support" ["is_active"]=> bool(true) }

      I cant overcome this problem right now, unfortunatelly (well I can
      just remove all default values from table definitions or use
      Doctrine_Query for updating staff.. but I'd like to use models

      However if I use Doctrine_Query of even

      $user = Doctrine_Core::getTable('App_Model_User')->find(1);

      instead of

      $user = new App_Model_User();
      $user->assignIdentifier(1);

      updates works well...

        Activity

        Hide
        Petr Peller added a comment -

        I second this.

        When you UPDATE row with save() method of Record after setting identifier by assignIdentifier() doctrine removes columns updates from SQL which are set to default values same as it would do with INSERT. Other columns are updated correctly. This is sure a bug.

        You can workaround this by setting the value as NULL instead of the actual default value. (Which I wouldn't recommend).

        Show
        Petr Peller added a comment - I second this. When you UPDATE row with save() method of Record after setting identifier by assignIdentifier() doctrine removes columns updates from SQL which are set to default values same as it would do with INSERT. Other columns are updated correctly. This is sure a bug. You can workaround this by setting the value as NULL instead of the actual default value. (Which I wouldn't recommend).

          People

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

            Dates

            • Created:
              Updated: