Commit b88f2e53 authored by Guilherme Blanco's avatar Guilherme Blanco

Merge pull request #287 from deeky666/fix-create-constraint-quotation

Fix platform create constraint foreign table name quotation
parents 45bdac96 11986f60
...@@ -1362,7 +1362,8 @@ abstract class AbstractPlatform ...@@ -1362,7 +1362,8 @@ abstract class AbstractPlatform
$foreignColumns[] = $column; $foreignColumns[] = $column;
} }
$referencesClause = ' REFERENCES '.$constraint->getForeignTableName(). ' ('.implode(', ', $foreignColumns).')'; $referencesClause = ' REFERENCES ' . $constraint->getQuotedForeignTableName($this) .
' (' . implode(', ', $foreignColumns) . ')';
} }
$query .= ' '.$columnList.$referencesClause; $query .= ' '.$columnList.$referencesClause;
......
...@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms; ...@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
...@@ -153,7 +154,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -153,7 +154,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk');
$sql = $this->_platform->getCreateConstraintSQL($fk, 'test'); $sql = $this->_platform->getCreateConstraintSQL($fk, 'test');
$this->assertEquals($this->getGenerateConstraintForeignKeySql(), $sql); $this->assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql);
} }
public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys()
...@@ -209,9 +210,11 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -209,9 +210,11 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
return 'ALTER TABLE test ADD CONSTRAINT constraint_name PRIMARY KEY (test)'; return 'ALTER TABLE test ADD CONSTRAINT constraint_name PRIMARY KEY (test)';
} }
public function getGenerateConstraintForeignKeySql() public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk)
{ {
return 'ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES foreign (id)'; $quotedForeignTable = $fk->getQuotedForeignTableName($this->_platform);
return "ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES $quotedForeignTable (id)";
} }
abstract public function getGenerateAlterTableSql(); abstract public function getGenerateAlterTableSql();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment