Skip to content
Browse files

Changed default flags (create indexes and create foreign keys) in Sql…

…itePlatform::getCreateTableSQL method
  • Loading branch information...
1 parent 16d0c3e commit 2a057e973d7c40feb19df7b2d7b796b7503e2ce0 @hason hason committed Nov 18, 2012
View
10 lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
@@ -638,6 +638,16 @@ public function getCreateConstraintSQL(Constraint $constraint, $table)
/**
* {@inheritDoc}
*/
+ public function getCreateTableSQL(Table $table, $createFlags = null)
+ {
+ $createFlags = null === $createFlags ? self::CREATE_INDEXES | self::CREATE_FOREIGNKEYS : $createFlags;
+
+ return parent::getCreateTableSQL($table, $createFlags);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function getListTableForeignKeysSQL($table, $database = null)
{
$table = str_replace('.', '__', $table);
View
27 tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Platforms;
+use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Platforms\SqlitePlatform;
@@ -202,6 +203,32 @@ public function testAlterTableAddComplexColumns()
}
}
+ public function testCreateTableWithDeferredForeignKeys()
+ {
+ $table = new Table('user');
+ $table->addColumn('id', 'integer');
+ $table->addColumn('article', 'integer');
+ $table->addColumn('post', 'integer');
+ $table->addColumn('parent', 'integer');
+ $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true));
+ $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true));
+ $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true));
+
+ $sql = array(
+ 'CREATE TABLE user ('
+ . 'article INTEGER NOT NULL, post INTEGER NOT NULL, parent INTEGER NOT NULL, id INTEGER NOT NULL'
+ . ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE'
+ . ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (post) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED'
+ . ', CONSTRAINT FK_8D93D6493D8E604F FOREIGN KEY (parent) REFERENCES user (id) DEFERRABLE INITIALLY DEFERRED'
+ . ')',
+ 'CREATE INDEX IDX_8D93D64923A0E66 ON user (article)',
+ 'CREATE INDEX IDX_8D93D6495A8A6C8D ON user (post)',
+ 'CREATE INDEX IDX_8D93D6493D8E604F ON user (parent)',
+ );
+
+ $this->assertEquals($sql, $this->_platform->getCreateTableSQL($table));
+ }
+
protected function getQuotedColumnInPrimaryKeySQL()
{
return array(

0 comments on commit 2a057e9

Please sign in to comment.
Something went wrong with that request. Please try again.