Changeset 1065 for branches

Show
Ignore:
Timestamp:
07/07/08 17:27:08 (5 months ago)
Author:
heltem
Message:

Add check for existance of nestedSetRightKey and nestedSetLeftKey attributes in nested set tables (closes #653)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/generator/classes/propel/engine/builder/om/php5/PHP5NestedSetPeerBuilder.php

    r1042 r1065  
    194194                $tableName = $table->getName(); 
    195195 
    196                 $left_colname = ''; 
    197                 $right_colname = ''; 
    198                 $scope_colname = null; 
    199                 $parent_colname = ''; 
     196                $colname = array(); 
    200197 
    201198                foreach ($table->getColumns() as $col) { 
    202199                        if ($col->isNestedSetLeftKey()) { 
    203                                 $left_colname = $this->prefixTablename($tableName) . '.' . strtoupper($col->getName()); 
     200                                $colname['left'] = $this->prefixTablename($tableName) . '.' . strtoupper($col->getName()); 
    204201                        } 
    205202 
    206203                        if ($col->isNestedSetRightKey()) { 
    207                                 $right_colname = $this->prefixTablename($tableName) . '.' . strtoupper($col->getName()); 
     204                                $colname['right'] = $this->prefixTablename($tableName) . '.' . strtoupper($col->getName()); 
    208205                        } 
    209206 
    210207                        if ($col->isTreeScopeKey()) { 
    211                                 $scope_colname = $this->prefixTablename($tableName) . '.' . strtoupper($col->getName()); 
     208                                $colname['scope'] = $this->prefixTablename($tableName) . '.' . strtoupper($col->getName()); 
    212209                        } 
    213210 
    214                         if (!empty($right_name) && !empty($left_colname) && !empty($scope_colname)) { 
     211                        if (3 == count($colname)) { 
    215212                                break; 
    216213                        } 
    217214                } 
     215 
     216                if(!isset($colname['left'])) { 
     217                        throw new EngineException("One column must have nestedSetLeftKey attribute set to true for [" . $table->getName() . "] table"); 
     218                } 
     219 
     220                if(!isset($colname['right'])) { 
     221                        throw new EngineException("One column must have nestedSetRightKey attribute set to true for [" . $table->getName() . "] table"); 
     222                } 
     223 
     224                $colname['scope'] = isset($colname['scope']) ? $colname['scope'] : null; 
     225 
    218226                $script .= " 
    219227        /** 
    220228         * Left column for the set 
    221229         */ 
    222         const LEFT_COL = " . var_export($left_colname, true) . "; 
     230        const LEFT_COL = " . var_export($colname['left'], true) . "; 
    223231 
    224232        /** 
    225233         * Right column for the set 
    226234         */ 
    227         const RIGHT_COL = " . var_export($right_colname, true) . "; 
     235        const RIGHT_COL = " . var_export($colname['right'], true) . "; 
    228236 
    229237        /** 
    230238         * Scope column for the set 
    231239         */ 
    232         const SCOPE_COL = " . var_export($scope_colname, true) . "; 
     240        const SCOPE_COL = " . var_export($colname['scope'], true) . "; 
    233241"; 
    234242        }