Skip to content

Commit db01604

Browse files
npoa-cmnicolas-grekas
authored andcommitted
Fix for recursive cascading in MS SQL Server
1 parent 744c6d5 commit db01604

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Dbal/Schema.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Acl\Dbal;
1313

14+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
1415
use Doctrine\DBAL\Schema\Schema as BaseSchema;
1516
use Doctrine\DBAL\Connection;
1617

@@ -22,12 +23,14 @@
2223
final class Schema extends BaseSchema
2324
{
2425
protected $options;
26+
protected $dbms;
2527

2628
/**
2729
* Constructor.
2830
*
2931
* @param array $options the names for tables
3032
* @param Connection $connection
33+
* @throws \Doctrine\DBAL\DBALException
3134
*/
3235
public function __construct(array $options, Connection $connection = null)
3336
{
@@ -36,6 +39,7 @@ public function __construct(array $options, Connection $connection = null)
3639
parent::__construct(array(), array(), $schemaConfig);
3740

3841
$this->options = $options;
42+
$this->dbms = $connection->getDatabasePlatform();
3943

4044
$this->addClassTable();
4145
$this->addSecurityIdentitiesTable();
@@ -134,7 +138,12 @@ protected function addObjectIdentityAncestorsTable()
134138

135139
$oidTable = $this->getTable($this->options['oid_table_name']);
136140
$table->addForeignKeyConstraint($oidTable, array('object_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
137-
$table->addForeignKeyConstraint($oidTable, array('ancestor_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
141+
// MS SQL Server does not support recursive cascading
142+
if ($this->dbms instanceof SQLServerPlatform) {
143+
$table->addForeignKeyConstraint($oidTable, array('ancestor_id'), array('id'), array('onDelete' => 'NO ACTION', 'onUpdate' => 'NO ACTION'));
144+
} else {
145+
$table->addForeignKeyConstraint($oidTable, array('ancestor_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
146+
}
138147
}
139148

140149
/**

0 commit comments

Comments
 (0)