Doctrine 1
  1. Doctrine 1
  2. DC-82

Conditional unique validator and index

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.4
    • Fix Version/s: 1.2.0-ALPHA3
    • Component/s: Import/Export
    • Labels:
      None

      Description

      Doctrine currently doesn't support conditional unique keys. One commonly happening situation is when we have a model with a column (eg. named "deleted") indicates whether the record was deleted and should no longer be treated as active. If we have an unique index on a "name" column, the index should contain only records with deleted = false. It also concerns an unique validation.

      I have prepared a patch for Doctrine_Validator_Unique and Doctrine_Export_Pgsql (Postgresql natively supports conditional indexes).

      Example of usage:

      public function setTableDefinition()
      {
        $this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true, 'sequence' => 'model_id_seq'));
        $this->hasColumn('name', 'string', 128, array('notnull', 'unique' => array('where' => 'deleted = false')));
        $this->hasColumn('deleted', 'boolean', 1, array('notnull', 'default' => false));
        $this->index('model_unique_name', array('fields' => array('name'), 'where' => 'deleted = false', 'type' => 'unique' ));
      }
      

        Issue Links

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Jonathan H. Wage
              Reporter:
              Jacek Dębowczyk
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: