コード例 #1
0
ファイル: SchemaBuilder.php プロジェクト: EchoWine/database
 /**
  * Drop the column
  *
  * @return result query
  */
 public function dropColumn($column)
 {
     if (($table = Schema::getTable($this->getTable())) == null) {
         return;
     }
     $c = $table->getColumn($column);
     if ($c == null) {
         return;
     }
     if ($c->getForeign()) {
         $this->query(DB::SQL()::DROP_FOREIGN_KEY($this->getTable(), $c->getConstraint()));
     }
     if ($c->getPrimary()) {
         $a = Schema::getTable($this->getTable());
         foreach (Schema::getAllForeignKeyToColumn($this->getTable(), $c->getName()) as $k) {
             $this->query(DB::SQL()::DROP_FOREIGN_KEY($this->getTable(), $k->getConstraint()));
             self::$tables[$k->getTable()]->getColumn($k->getName())->resetForeign($k);
         }
         $this->query(DB::SQL()::MODIFY_COLUMN_RESET($this->getTable(), $c->getName()));
         $this->query(DB::SQL()::DROP_PRIMARY_KEY($this->getTable()));
     } else {
         if ($c->hasIndex()) {
             $this->query(DB::SQL()::DROP_INDEX_KEY($this->getTable(), $c->getIndex()));
         }
     }
     if ($table->countColumns() == 1) {
         unset(Schema::$tables[$this->getTable()]);
         unset(self::$tables[$this->getTable()]);
         return $this->drop();
     } else {
         Schema::$tables[$this->getTable()]->dropColumn($c->getName());
         self::$tables[$this->getTable()]->dropColumn($c->getName());
         return $this->query(DB::SQL()::DROP_COLUMN($this->getTable(), $c->getName()));
     }
 }