mootensai\enhancedgii\BaseGenerator::checkPivotTable PHP Method

checkPivotTable() protected method

For simplicity, this method only deals with the case where the pivot contains two PK columns, each referencing a column in a different table.
protected checkPivotTable ( yii\db\TableSchema $table ) : array | boolean
$table yii\db\TableSchema
return array | boolean the relevant foreign key constraint information if the table is a junction table, or false if the table is not a junction table.
    protected function checkPivotTable($table)
    {
        $pk = $table->primaryKey;
        if (count($pk) !== 2) {
            return false;
        }
        $fks = [];
        foreach ($table->foreignKeys as $refs) {
            if (count($refs) === 2) {
                if (isset($refs[$pk[0]])) {
                    $fks[$pk[0]] = [$refs[0], $refs[$pk[0]]];
                } elseif (isset($refs[$pk[1]])) {
                    $fks[$pk[1]] = [$refs[0], $refs[$pk[1]]];
                }
            }
        }
        if (count($fks) === 2 && $fks[$pk[0]][0] !== $fks[$pk[1]][0]) {
            return $fks;
        } else {
            return false;
        }
    }