/**
  * This is called before generating the code file.
  */
 public function beforeGenerate()
 {
     $keyColumns = [];
     foreach ($this->columns as $column) {
         if (in_array($column->type, Column::primaryKeyTypes())) {
             $keyColumns[] = $column;
         }
     }
     if (count($keyColumns) < 2) {
         return;
     }
     $fallback = Column::keyFallbackTypes();
     $this->compositeKey = [];
     foreach ($keyColumns as $keyColumn) {
         if (!isset($fallback[$keyColumn->type])) {
             throw new Exception("Unknown fallback for primary key type: {$keyColumn->type}");
         }
         $keyColumn->overrideType = $fallback[$keyColumn->type];
         $this->compositeKey[] = $keyColumn->name;
     }
 }
 /**
  * @inheritdoc
  */
 public function load($data, $formName = null)
 {
     if (!parent::load($data, $formName)) {
         return false;
     }
     $this->migrationName = preg_replace('/\\s+/', '_', $this->migrationName);
     $dataFix = ['Table' => [], 'Column' => []];
     if (isset($data['Table'])) {
         foreach ($data['Table'] as $temp) {
             $dataFix['Table'][] = $temp;
         }
     }
     if (isset($data['Column'])) {
         foreach ($data['Column'] as $temp) {
             $columnFix = [];
             foreach ($temp as $colTemp) {
                 $columnFix[] = $colTemp;
             }
             $temp = $columnFix;
             $dataFix['Column'][] = $temp;
         }
     }
     if (isset($data['Index'])) {
         foreach ($data['Index'] as $temp) {
             $dataFix['Index'][] = $temp;
         }
     }
     if (isset($data['ForeignKey'])) {
         foreach ($data['ForeignKey'] as $temp) {
             $dataFix['ForeignKey'][] = $temp;
         }
     }
     $data = $dataFix;
     if (isset($data['Table'])) {
         $this->tables = static::createMultiple(Table::className(), [], $data);
         Table::loadMultiple($this->tables, $data);
         $loadData = [];
         for ($i = 0; $i < count($this->tables); ++$i) {
             $loadData['Column'] = $data['Column'][$i];
             $this->tables[$i]->columns = static::createMultiple(Column::className(), [], $loadData);
             $this->tables[$i]->isNewRecord = false;
             Column::loadMultiple($this->tables[$i]->columns, $loadData);
         }
     } else {
         $this->tables = [new Table()];
     }
     if (isset($data['Index'])) {
         $this->indices = static::createMultiple(Index::className(), [], $data);
         Index::loadMultiple($this->indices, $data);
         foreach ($this->indices as $index) {
             $index->isNewRecord = false;
         }
     } else {
         $this->indices = [new Index()];
     }
     if (isset($data['ForeignKey'])) {
         $this->foreignKeys = static::createMultiple(ForeignKey::className(), [], $data);
         ForeignKey::loadMultiple($this->foreignKeys, $data);
         foreach ($this->foreignKeys as $fKey) {
             $fKey->isNewRecord = false;
         }
     } else {
         $this->foreignKeys = [new ForeignKey()];
     }
     return true;
 }