Skip to content

Commit 953fa2e

Browse files
npoa-cmwouterj
authored andcommitted
Fix for recursive cascading in MS SQL Server
1 parent faf9ede commit 953fa2e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Dbal/Schema.php

Lines changed: 10 additions & 2 deletions
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();
@@ -129,8 +132,13 @@ protected function addObjectIdentityAncestorsTable()
129132
$table->setPrimaryKey(['object_identity_id', 'ancestor_id']);
130133

131134
$oidTable = $this->getTable($this->options['oid_table_name']);
132-
$table->addForeignKeyConstraint($oidTable, ['object_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
133-
$table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
135+
$action = 'CASCADE';
136+
if ($this->platform instanceof SQLServerPlatform) {
137+
// MS SQL Server does not support recursive cascading
138+
$action = 'NO ACTION';
139+
}
140+
$table->addForeignKeyConstraint($oidTable, ['object_identity_id'], ['id'], ['onDelete' => $action, 'onUpdate' => $action]);
141+
$table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => $action, 'onUpdate' => $action]);
134142
}
135143

136144
/**

0 commit comments

Comments
 (0)