protected function addFixLevels(&$script)
 {
     $objectClassName = $this->objectClassName;
     $queryClassName = $this->queryClassName;
     $tableMapClassName = $this->tableMapClassName;
     $useScope = $this->behavior->useScope();
     $script .= "\n/**\n * Update the tree to allow insertion of a leaf at the specified position\n *";
     if ($useScope) {
         $script .= "\n * @param      integer \$scope    scope column value";
     }
     $script .= "\n * @param      ConnectionInterface \$con    Connection to use.\n */\nstatic public function fixLevels(" . ($useScope ? "\$scope, " : "") . "ConnectionInterface \$con = null)\n{\n    \$c = new Criteria();";
     if ($useScope) {
         $script .= "\n    \$c->add({$objectClassName}::SCOPE_COL, \$scope, Criteria::EQUAL);";
     }
     $script .= "\n    \$c->addAscendingOrderByColumn({$objectClassName}::LEFT_COL);\n    \$dataFetcher = {$queryClassName}::create(null, \$c)->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find(\$con);\n    ";
     if (!$this->table->getChildrenColumn()) {
         $script .= "\n    // set the class once to avoid overhead in the loop\n    \$cls = {$tableMapClassName}::getOMClass(false);";
     }
     $script .= "\n    \$level = null;\n    // iterate over the statement\n    while (\$row = \$dataFetcher->fetch()) {\n\n        // hydrate object\n        \$key = {$tableMapClassName}::getPrimaryKeyHashFromRow(\$row, 0);\n        /** @var \$obj {$objectClassName} */\n        if (null === (\$obj = {$tableMapClassName}::getInstanceFromPool(\$key))) {";
     if ($this->table->getChildrenColumn()) {
         $script .= "\n            // class must be set each time from the record row\n            \$cls = {$tableMapClassName}::getOMClass(\$row, 0);\n            \$cls = substr('.'.\$cls, strrpos('.'.\$cls, '.') + 1);\n            " . $this->builder->buildObjectInstanceCreationCode('$obj', '$cls') . "\n            \$obj->hydrate(\$row);\n            {$tableMapClassName}::addInstanceToPool(\$obj, \$key);";
     } else {
         $script .= "\n            " . $this->builder->buildObjectInstanceCreationCode('$obj', '$cls') . "\n            \$obj->hydrate(\$row);\n            {$tableMapClassName}::addInstanceToPool(\$obj, \$key);";
     }
     $script .= "\n        }\n\n        // compute level\n        // Algorithm shamelessly stolen from sfPropelActAsNestedSetBehaviorPlugin\n        // Probably authored by Tristan Rivoallan\n        if (\$level === null) {\n            \$level = 0;\n            \$i = 0;\n            \$prev = array(\$obj->getRightValue());\n        } else {\n            while (\$obj->getRightValue() > \$prev[\$i]) {\n                \$i--;\n            }\n            \$level = ++\$i;\n            \$prev[\$i] = \$obj->getRightValue();\n        }\n\n        // update level in node if necessary\n        if (\$obj->getLevel() !== \$level) {\n            \$obj->setLevel(\$level);\n            \$obj->save(\$con);\n        }\n    }\n    \$dataFetcher->close();\n}\n";
 }
 public function testAddColumn()
 {
     $table = new Table('books');
     $column = $this->getColumnMock('created_at');
     $this->assertInstanceOf('Propel\\Generator\\Model\\Column', $table->addColumn($column));
     $this->assertNull($table->getChildrenColumn());
     $this->assertTrue($table->requiresTransactionInPostgres());
     $this->assertTrue($table->hasColumn($column));
     $this->assertTrue($table->hasColumn('CREATED_AT', true));
     $this->assertSame($column, $table->getColumnByPhpName('CreatedAt'));
     $this->assertCount(1, $table->getColumns());
     $this->assertSame(1, $table->getNumColumns());
 }