public function removeField($model, $field)
    {
        // Special-case implicit M2M tables
        if ($field->manyToMany && $field->relation->through->getMeta()->autoCreated) {
            $this->deleteModel($field->relation->through);

            return;
        }
        $type = $field->dbType($this->connection);
        $name = $field->getColumnName();

        // It might not actually have a column behind it
        if (empty($type)) {
            return;
        }
        $table = $model->getMeta()->getDbTable();
        $tableDef = new TableDiff($table);
        // Drop any FK constraints, MySQL requires explicit deletion
        if ($field->isRelation && null !== $field->relation) {
            foreach ($this->constraintName($table, $name, ['foreignKey' => true]) as $fkConstraint) {
                $tableDef->removedForeignKeys[] = $fkConstraint;
            }
        }

        // if its pk we need to drop  fk constraints that point to us
        if ($field->primaryKey) {
            $newRels = $field->scopeModel->getMeta()->getReverseRelatedObjects();
            /** @var $newRel RelatedField */
            foreach ($newRels as $newRel) {
                $fkConstraints = $this->constraintName(
                    $newRel->scopeModel->getMeta()->getDbTable(),
                    $newRel->getColumnName(),
                    ['foreignKey' => true]
                );
                $relDiff = new TableDiff($newRel->scopeModel->getMeta()->getDbTable());
                $relDiff->removedForeignKeys = $fkConstraints;
                $this->alterTable($relDiff);
            }
        }

        // remove column
        $tableDef->removedColumns[] = new Column($name, Type::getType($type));

        $this->alterTable($tableDef);
    }
public function removeField($model, $field)
    {
        // Special-case implicit M2M tables
        if ($field->manyToMany && $field->relation->through->getMeta()->autoCreated) {
            $this->deleteModel($field->relation->through);

            return;
        }
        $type = $field->dbType($this->connection);
        $name = $field->getColumnName();

        // It might not actually have a column behind it
        if (empty($type)) {
            return;
        }
        $table = $model->getMeta()->getDbTable();
        $tableDef = new TableDiff($table);
        // Drop any FK constraints, MySQL requires explicit deletion
        if ($field->isRelation && null !== $field->relation) {
            foreach ($this->constraintName($table, $name, ['foreignKey' => true]) as $fkConstraint) {
                $tableDef->removedForeignKeys[] = $fkConstraint;
            }
        }

        // if its pk we need to drop  fk constraints that point to us
        if ($field->primaryKey) {
            $newRels = $field->scopeModel->getMeta()->getReverseRelatedObjects();
            /** @var $newRel RelatedField */
            foreach ($newRels as $newRel) {
                $fkConstraints = $this->constraintName(
                    $newRel->scopeModel->getMeta()->getDbTable(),
                    $newRel->getColumnName(),
                    ['foreignKey' => true]
                );
                $relDiff = new TableDiff($newRel->scopeModel->getMeta()->getDbTable());
                $relDiff->removedForeignKeys = $fkConstraints;
                $this->alterTable($relDiff);
            }
        }

        // remove column
        $tableDef->removedColumns[] = new Column($name, Type::getType($type));

        $this->alterTable($tableDef);
    }
public function removeField ( $ model , $ field ) { // Special-case implicit M2M tables if ( $ field -> manyToMany && $ field -> relation -> through -> getMeta ( ) -> autoCreated ) { $ this -> deleteModel ( $ field -> relation -> through ) ; return ; } $ type = $ field -> dbType ( $ this -> connection ) ; $ name = $ field -> getColumnName ( ) ; // It might not actually have a column behind it if ( empty ( $ type ) ) { return ; } $ table = $ model -> getMeta ( ) -> getDbTable ( ) ; $ tableDef = new TableDiff ( $ table ) ; // Drop any FK constraints, MySQL requires explicit deletion if ( $ field -> isRelation && null !== $ field -> relation ) { foreach ( $ this -> constraintName ( $ table , $ name , [ 'foreignKey' => true ] ) as $ fkConstraint ) { $ tableDef -> removedForeignKeys [ ] = $ fkConstraint ; } } // if its pk we need to drop  fk constraints that point to us if ( $ field -> primaryKey ) { $ newRels = $ field -> scopeModel -> getMeta ( ) -> getReverseRelatedObjects ( ) ; /** @var $newRel RelatedField */ foreach ( $ newRels as $ newRel ) { $ fkConstraints = $ this -> constraintName ( $ newRel -> scopeModel -> getMeta ( ) -> getDbTable ( ) , $ newRel -> getColumnName ( ) , [ 'foreignKey' => true ] ) ; $ relDiff = new TableDiff ( $ newRel -> scopeModel -> getMeta ( ) -> getDbTable ( ) ) ; $ relDiff -> removedForeignKeys = $ fkConstraints ; $ this -> alterTable ( $ relDiff ) ; } } // remove column $ tableDef -> removedColumns [ ] = new Column ( $ name , Type :: getType ( $ type ) ) ; $ this -> alterTable ( $ tableDef ) ; }
Removes a field from a model. Usually involves deleting a column, but for M2Ms may involve deleting a table.

@param Model $model
@param Field $field

@throws \Doctrine\DBAL\Schema\SchemaException
@throws \Eddmash\PowerOrm\Exception\LookupError

@since  1.1.0

@author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>

@throws \Doctrine\DBAL\DBALException
Removes a field from a model . Usually involves deleting a column but for M2Ms may involve deleting a table .