private function generateForeignKey($table)
    {
        if (empty($table->foreignKeys)) {
            return;
        }
        $definition = "// fk: $table->name\n";

        foreach ($table->foreignKeys as $fk) {
            $refTable = '';
            $refColumns = '';
            $columns = '';

            foreach ($fk as $k => $v) {
                if (0 === $k) {
                    $refTable = $v;
                } else {
                    $columns = $k;
                    $refColumns = $v;
                }
            }
            $definition .= sprintf("\$this->addForeignKey('%s', '{{%%%s}}', '%s', '{{%%%s}}', '%s');\n",
                'fk_'.$table->name.'_'.$columns, $table->name, $columns, $refTable, $refColumns);
        }
        return "$definition\n";
    }
private function generateForeignKey($table)
    {
        if (empty($table->foreignKeys)) {
            return;
        }
        $definition = "// fk: $table->name\n";

        foreach ($table->foreignKeys as $fk) {
            $refTable = '';
            $refColumns = '';
            $columns = '';

            foreach ($fk as $k => $v) {
                if (0 === $k) {
                    $refTable = $v;
                } else {
                    $columns = $k;
                    $refColumns = $v;
                }
            }
            $definition .= sprintf("\$this->addForeignKey('%s', '{{%%%s}}', '%s', '{{%%%s}}', '%s');\n",
                'fk_'.$table->name.'_'.$columns, $table->name, $columns, $refTable, $refColumns);
        }
        return "$definition\n";
    }
private function generateForeignKey ( $ table ) { if ( empty ( $ table -> foreignKeys ) ) { return ; } $ definition = "// fk: $table->name\n" ; foreach ( $ table -> foreignKeys as $ fk ) { $ refTable = '' ; $ refColumns = '' ; $ columns = '' ; foreach ( $ fk as $ k => $ v ) { if ( 0 === $ k ) { $ refTable = $ v ; } else { $ columns = $ k ; $ refColumns = $ v ; } } $ definition .= sprintf ( "\$this->addForeignKey('%s', '{{%%%s}}', '%s', '{{%%%s}}', '%s');\n" , 'fk_' . $ table -> name . '_' . $ columns , $ table -> name , $ columns , $ refTable , $ refColumns ) ; } return "$definition\n" ; }
Returns the foreign key definition.
@param TableSchema[] $table
@return string|null foreign key definition or null
Returns the foreign key definition .