public function relateToOtherTables(array $otherTables)
    {
        if ($calls = $this->getGenericCalls()) {
            $tablesByModelName = [];

            /** @var TableMigration $tableObject */
            foreach ($otherTables as $tableObject) {
                $tablesByModelName[$tableObject->getModelName()] = $tableObject;
            } // foreach

            /** @var ForeignKey $call */
            foreach ($calls as $call) {
                if ($on = $call->on) {
                    /** @var TableMigration $otherTable */
                    $otherTable = @$otherTables[$on];
                    $call->on = $otherTable->getName();

                    $otherCall = clone $call;

                    if ($this->isPivotTable()) {
                        $modelNames = array_map('ucfirst', explode('_', $tableName = $this->getName()));

                        $matchedModelTables = array_intersect_key($tablesByModelName, array_flip($modelNames));
                        unset($matchedModelTables[$otherTable->getModelName()]);

                        $otherCall->isForMany(true);
                        $otherCall->isForPivotTable(true);

                        $call->on = current($matchedModelTables)->getName();
                        $otherTable->addGenericCall($otherCall->setRelatedTable(current($matchedModelTables)));
                    } // if
                    else {
                        $call->setRelatedTable($otherTable);
                        $otherTable->addAsRelationSource($otherCall->setRelatedTable($this));
                    } // else
                } // if
            } // foreach
        } // if

        return $this;
    }
public function relateToOtherTables(array $otherTables)
    {
        if ($calls = $this->getGenericCalls()) {
            $tablesByModelName = [];

            /** @var TableMigration $tableObject */
            foreach ($otherTables as $tableObject) {
                $tablesByModelName[$tableObject->getModelName()] = $tableObject;
            } // foreach

            /** @var ForeignKey $call */
            foreach ($calls as $call) {
                if ($on = $call->on) {
                    /** @var TableMigration $otherTable */
                    $otherTable = @$otherTables[$on];
                    $call->on = $otherTable->getName();

                    $otherCall = clone $call;

                    if ($this->isPivotTable()) {
                        $modelNames = array_map('ucfirst', explode('_', $tableName = $this->getName()));

                        $matchedModelTables = array_intersect_key($tablesByModelName, array_flip($modelNames));
                        unset($matchedModelTables[$otherTable->getModelName()]);

                        $otherCall->isForMany(true);
                        $otherCall->isForPivotTable(true);

                        $call->on = current($matchedModelTables)->getName();
                        $otherTable->addGenericCall($otherCall->setRelatedTable(current($matchedModelTables)));
                    } // if
                    else {
                        $call->setRelatedTable($otherTable);
                        $otherTable->addAsRelationSource($otherCall->setRelatedTable($this));
                    } // else
                } // if
            } // foreach
        } // if

        return $this;
    }
public function relateToOtherTables ( array $ otherTables ) { if ( $ calls = $ this -> getGenericCalls ( ) ) { $ tablesByModelName = [ ] ; /** @var TableMigration $tableObject */ foreach ( $ otherTables as $ tableObject ) { $ tablesByModelName [ $ tableObject -> getModelName ( ) ] = $ tableObject ; } // foreach /** @var ForeignKey $call */ foreach ( $ calls as $ call ) { if ( $ on = $ call -> on ) { /** @var TableMigration $otherTable */ $ otherTable = @ $ otherTables [ $ on ] ; $ call -> on = $ otherTable -> getName ( ) ; $ otherCall = clone $ call ; if ( $ this -> isPivotTable ( ) ) { $ modelNames = array_map ( 'ucfirst' , explode ( '_' , $ tableName = $ this -> getName ( ) ) ) ; $ matchedModelTables = array_intersect_key ( $ tablesByModelName , array_flip ( $ modelNames ) ) ; unset ( $ matchedModelTables [ $ otherTable -> getModelName ( ) ] ) ; $ otherCall -> isForMany ( true ) ; $ otherCall -> isForPivotTable ( true ) ; $ call -> on = current ( $ matchedModelTables ) -> getName ( ) ; $ otherTable -> addGenericCall ( $ otherCall -> setRelatedTable ( current ( $ matchedModelTables ) ) ) ; } // if else { $ call -> setRelatedTable ( $ otherTable ) ; $ otherTable -> addAsRelationSource ( $ otherCall -> setRelatedTable ( $ this ) ) ; } // else } // if } // foreach } // if return $ this ; }
Relates this table to others.
@param TableMigration[] $otherTables
@return TableMigration
Relates this table to others .