Doctrine 1
  1. Doctrine 1
  2. DC-92

Doctrine_Import_Pgsql::listTableColumns() creates wrong default values for boolean fields

    Details

      Description

      When importing a db table as a model, we see the following for a boolean field:

              $this->hasColumn('is_blocked', 'boolean', 1, array(
                   'type' => 'boolean',
                   'length' => 1,
                   'fixed' => false,
                   'unsigned' => false,
                   'notnull' => true,
                   'default' => 'false',   // <----- this field not 0, 1 or a boolean, but a string literal linstead
                   'primary' => false,
                   ));
      

      Creating an object and immediately saving it results in two validation errors for this field:

      1. The field is not boolean, but string
      2. The field is not length 1, but length 5 (string "false")

      I applied the following patch to the listTableColumns() function:

                  elseif (preg_match("/^'(.*)'::character varying$/", $description['default'], $matches)) {
                      $description['default'] = $matches[1];
                  }
      +           elseif ($description['type'] == 'boolean') {
      +               if ($description['default'] === 'true') {
      +                   $description['default'] = true;
      +               } elseif ($description['default'] === 'false') {
      +                   $description['default'] = false;
      +               }
      +           }
      
                  $columns[$val['field']] = $description;
      

      This makes the import work as expected for us.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Maurice Makaay
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: