Пример #1
0
 /**
  * @param TableSchema $table
  */
 public function fix(TableSchema $table)
 {
     $this->key = $table->primaryKey;
     $this->isForeignKey = false;
     foreach ($this->key as $columnName) {
         foreach ($table->foreignKeys as $foreignKey) {
             unset($foreignKey[0]);
             if (array_key_exists($columnName, $foreignKey)) {
                 $this->isForeignKey = true;
                 break;
             }
         }
         if ($this->isForeignKey) {
             break;
         }
     }
     $this->isStatic = false;
     if (!$this->isForeignKey && $this->getCount() == 1) {
         $column = $table->getColumn($this->key[0]);
         if ($column && $column->getIsInteger() && $column->size == 3 && $column->unsigned) {
             $this->isStatic = !$column->autoIncrement;
         }
     }
 }
Пример #2
0
 /**
  * @param TableSchema $table
  */
 protected function findTitleKey(TableSchema $table)
 {
     foreach ($table->uniqueKeys as $uniqueKey) {
         $types = [];
         foreach ($uniqueKey as $columnName) {
             $types[] = $table->getColumn($columnName)->type;
         }
         if (in_array(Schema::TYPE_CHAR, $types) || in_array(Schema::TYPE_STRING, $types)) {
             $table->titleKey = $uniqueKey;
             break;
         }
     }
     if (!count($table->titleKey)) {
         foreach ($table->columns as $column) {
             if (preg_match('~^tk_~', $column->name)) {
                 $table->titleKey[] = $column->name;
             }
         }
         if (!count($table->titleKey)) {
             $table->titleKey = $table->primaryKey;
         }
     }
 }