Skip to content

Commit 82718a3

Browse files
npoa-cmwouterj
authored andcommitted
Fix for recursive cascading in MS SQL Server
1 parent 8234bd3 commit 82718a3

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
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Acl\Dbal;
1313

1414
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
1516
use Doctrine\DBAL\Schema\Schema as BaseSchema;
1617
use Doctrine\DBAL\Schema\SchemaConfig;
1718

@@ -23,6 +24,7 @@
2324
final class Schema extends BaseSchema
2425
{
2526
protected $options;
27+
protected $platform;
2628

2729
/**
2830
* @param array $options the names for tables
@@ -34,6 +36,7 @@ public function __construct(array $options, Connection $connection = null)
3436
parent::__construct([], [], $schemaConfig);
3537

3638
$this->options = $options;
39+
$this->platform = $connection ? $connection->getDatabasePlatform() : null;
3740

3841
$this->addClassTable();
3942
$this->addSecurityIdentitiesTable();
@@ -128,9 +131,15 @@ protected function addObjectIdentityAncestorsTable()
128131

129132
$table->setPrimaryKey(['object_identity_id', 'ancestor_id']);
130133

134+
$cascade = 'CASCADE';
135+
// MS SQL Server does not support recursive cascading
136+
if ($this->platform instanceof SQLServerPlatform) {
137+
$cascade = 'NO ACTION';
138+
}
139+
131140
$oidTable = $this->getTable($this->options['oid_table_name']);
132141
$table->addForeignKeyConstraint($oidTable, ['object_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
133-
$table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
142+
$table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => $cascade, 'onUpdate' => $cascade]);
134143
}
135144

136145
/**

0 commit comments

Comments
 (0)