Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
a0cb862e
Commit
a0cb862e
authored
Jan 21, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-204' into 2.2
parents
480b127f
60326287
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
Table.php
lib/Doctrine/DBAL/Schema/Table.php
+10
-0
RemoveNamespacedAssets.php
lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php
+4
-0
RemoveNamespacedAssetsTest.php
.../Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php
+25
-0
No files found.
lib/Doctrine/DBAL/Schema/Table.php
View file @
a0cb862e
...
...
@@ -465,6 +465,16 @@ class Table extends AbstractAsset
return
$this
->
_fkConstraints
[
$constraintName
];
}
public
function
removeForeignKey
(
$constraintName
)
{
$constraintName
=
strtolower
(
$constraintName
);
if
(
!
$this
->
hasForeignKey
(
$constraintName
))
{
throw
SchemaException
::
foreignKeyDoesNotExist
(
$constraintName
,
$this
->
_name
);
}
unset
(
$this
->
_fkConstraints
[
$constraintName
]);
}
/**
* @return Column[]
*/
...
...
lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php
View file @
a0cb862e
...
...
@@ -89,6 +89,10 @@ class RemoveNamespacedAssets implements Visitor
*/
public
function
acceptForeignKey
(
Table
$localTable
,
ForeignKeyConstraint
$fkConstraint
)
{
$foreignTable
=
$this
->
schema
->
getTable
(
$fkConstraint
->
getForeignTableName
());
if
(
!
$foreignTable
->
isInDefaultNamespace
(
$this
->
schema
->
getName
())
)
{
$localTable
->
removeForeignKey
(
$fkConstraint
->
getName
());
}
}
/**
...
...
tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php
View file @
a0cb862e
...
...
@@ -5,6 +5,7 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\SchemaConfig
;
use
Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
class
RemoveNamespacedAssetsTest
extends
\PHPUnit_Framework_TestCase
{
...
...
@@ -26,4 +27,28 @@ class RemoveNamespacedAssetsTest extends \PHPUnit_Framework_TestCase
$tables
=
$schema
->
getTables
();
$this
->
assertEquals
(
array
(
"test.test"
,
"test.baz"
),
array_keys
(
$tables
),
"Only 2 tables should be present, both in 'test' namespace."
);
}
/**
* @group DBAL-204
*/
public
function
testCleanupForeignKeys
()
{
$config
=
new
SchemaConfig
;
$config
->
setName
(
"test"
);
$schema
=
new
Schema
(
array
(),
array
(),
$config
);
$testTable
=
$schema
->
createTable
(
"test.test"
);
$testTable
->
addColumn
(
'id'
,
'integer'
);
$fooTable
=
$schema
->
createTable
(
"foo.bar"
);
$fooTable
->
addColumn
(
'id'
,
'integer'
);
$testTable
->
addForeignKeyConstraint
(
"foo.bar"
,
array
(
"id"
),
array
(
"id"
));
$schema
->
visit
(
new
RemoveNamespacedAssets
());
$sql
=
$schema
->
toSql
(
new
MySqlPlatform
());
$this
->
assertEquals
(
1
,
count
(
$sql
),
"Just one CREATE TABLE statement, no foreign key and table to foo.bar"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment