12
12
namespace Symfony \Component \Security \Acl \Dbal ;
13
13
14
14
use Doctrine \DBAL \Connection ;
15
+ use Doctrine \DBAL \Platforms \SQLServerPlatform ;
15
16
use Doctrine \DBAL \Schema \Schema as BaseSchema ;
16
17
use Doctrine \DBAL \Schema \SchemaConfig ;
17
18
23
24
final class Schema extends BaseSchema
24
25
{
25
26
protected $ options ;
27
+ protected $ platform ;
26
28
27
29
/**
28
30
* @param array $options the names for tables
@@ -34,6 +36,7 @@ public function __construct(array $options, Connection $connection = null)
34
36
parent ::__construct ([], [], $ schemaConfig );
35
37
36
38
$ this ->options = $ options ;
39
+ $ this ->platform = $ connection ? $ connection ->getDatabasePlatform () : null ;
37
40
38
41
$ this ->addClassTable ();
39
42
$ this ->addSecurityIdentitiesTable ();
@@ -129,8 +132,13 @@ protected function addObjectIdentityAncestorsTable()
129
132
$ table ->setPrimaryKey (['object_identity_id ' , 'ancestor_id ' ]);
130
133
131
134
$ 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 ]);
134
142
}
135
143
136
144
/**
0 commit comments