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
c3ef0195
Commit
c3ef0195
authored
Nov 13, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-145] Fixed.
parent
94d77117
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
22 deletions
+62
-22
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+28
-22
BasicFunctionalTest.php
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
+34
-0
No files found.
lib/Doctrine/ORM/UnitOfWork.php
View file @
c3ef0195
...
...
@@ -629,6 +629,11 @@ class UnitOfWork implements PropertyChangedListener
if
(
!
isset
(
$this
->
_entityStates
[
$oid
])
||
$this
->
_entityStates
[
$oid
]
!=
self
::
STATE_MANAGED
)
{
throw
new
\InvalidArgumentException
(
'Entity must be managed.'
);
}
/* TODO: Just return if changetracking policy is NOTIFY?
if ($class->isChangeTrackingNotify()) {
return;
}*/
if
(
!
$class
->
isInheritanceTypeNone
())
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
...
...
@@ -690,7 +695,7 @@ class UnitOfWork implements PropertyChangedListener
$postInsertIds
=
$persister
->
executeInserts
();
if
(
$postInsertIds
)
{
// Persister returned
a
post-insert IDs
// Persister returned post-insert IDs
foreach
(
$postInsertIds
as
$id
=>
$entity
)
{
$oid
=
spl_object_hash
(
$entity
);
$idField
=
$class
->
identifier
[
0
];
...
...
@@ -1477,12 +1482,16 @@ class UnitOfWork implements PropertyChangedListener
private
function
_cascadeRefresh
(
$entity
,
array
&
$visited
)
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
foreach
(
$class
->
associationMappings
as
$assoc
Mapping
)
{
if
(
!
$assoc
Mapping
->
isCascadeRefresh
)
{
foreach
(
$class
->
associationMappings
as
$assoc
)
{
if
(
!
$assoc
->
isCascadeRefresh
)
{
continue
;
}
$relatedEntities
=
$class
->
reflFields
[
$assoc
Mapping
->
sourceFieldName
]
->
getValue
(
$entity
);
$relatedEntities
=
$class
->
reflFields
[
$assoc
->
sourceFieldName
]
->
getValue
(
$entity
);
if
(
$relatedEntities
instanceof
Collection
)
{
if
(
$relatedEntities
instanceof
PersistentCollection
)
{
// Unwrap so that foreach() does not initialize
$relatedEntities
=
$relatedEntities
->
unwrap
();
}
foreach
(
$relatedEntities
as
$relatedEntity
)
{
$this
->
_doRefresh
(
$relatedEntity
,
$visited
);
}
...
...
@@ -1501,11 +1510,11 @@ class UnitOfWork implements PropertyChangedListener
private
function
_cascadeDetach
(
$entity
,
array
&
$visited
)
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
foreach
(
$class
->
associationMappings
as
$assoc
Mapping
)
{
if
(
!
$assoc
Mapping
->
isCascadeDetach
)
{
foreach
(
$class
->
associationMappings
as
$assoc
)
{
if
(
!
$assoc
->
isCascadeDetach
)
{
continue
;
}
$relatedEntities
=
$class
->
reflFields
[
$assoc
Mapping
->
sourceFieldName
]
->
getValue
(
$entity
);
$relatedEntities
=
$class
->
reflFields
[
$assoc
->
sourceFieldName
]
->
getValue
(
$entity
);
if
(
$relatedEntities
instanceof
Collection
)
{
if
(
$relatedEntities
instanceof
PersistentCollection
)
{
// Unwrap so that foreach() does not initialize
...
...
@@ -1530,21 +1539,21 @@ class UnitOfWork implements PropertyChangedListener
private
function
_cascadeMerge
(
$entity
,
$managedCopy
,
array
&
$visited
)
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
foreach
(
$class
->
associationMappings
as
$assoc
Mapping
)
{
if
(
!
$assoc
Mapping
->
isCascadeMerge
)
{
foreach
(
$class
->
associationMappings
as
$assoc
)
{
if
(
!
$assoc
->
isCascadeMerge
)
{
continue
;
}
$relatedEntities
=
$class
->
reflFields
[
$assoc
Mapping
->
sourceFieldName
]
->
getValue
(
$entity
);
$relatedEntities
=
$class
->
reflFields
[
$assoc
->
sourceFieldName
]
->
getValue
(
$entity
);
if
(
$relatedEntities
instanceof
Collection
)
{
if
(
$relatedEntities
instanceof
PersistentCollection
)
{
// Unwrap so that foreach() does not initialize
$relatedEntities
=
$relatedEntities
->
unwrap
();
}
foreach
(
$relatedEntities
as
$relatedEntity
)
{
$this
->
_doMerge
(
$relatedEntity
,
$visited
,
$managedCopy
,
$assoc
Mapping
);
$this
->
_doMerge
(
$relatedEntity
,
$visited
,
$managedCopy
,
$assoc
);
}
}
else
if
(
$relatedEntities
!==
null
)
{
$this
->
_doMerge
(
$relatedEntities
,
$visited
,
$managedCopy
,
$assoc
Mapping
);
$this
->
_doMerge
(
$relatedEntities
,
$visited
,
$managedCopy
,
$assoc
);
}
}
}
...
...
@@ -1559,11 +1568,11 @@ class UnitOfWork implements PropertyChangedListener
private
function
_cascadePersist
(
$entity
,
array
&
$visited
)
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
foreach
(
$class
->
associationMappings
as
$assoc
Mapping
)
{
if
(
!
$assoc
Mapping
->
isCascadePersist
)
{
foreach
(
$class
->
associationMappings
as
$assoc
)
{
if
(
!
$assoc
->
isCascadePersist
)
{
continue
;
}
$relatedEntities
=
$class
->
reflFields
[
$assoc
Mapping
->
sourceFieldName
]
->
getValue
(
$entity
);
$relatedEntities
=
$class
->
reflFields
[
$assoc
->
sourceFieldName
]
->
getValue
(
$entity
);
if
((
$relatedEntities
instanceof
Collection
||
is_array
(
$relatedEntities
)))
{
if
(
$relatedEntities
instanceof
PersistentCollection
)
{
// Unwrap so that foreach() does not initialize
...
...
@@ -1587,16 +1596,13 @@ class UnitOfWork implements PropertyChangedListener
private
function
_cascadeRemove
(
$entity
,
array
&
$visited
)
{
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
foreach
(
$class
->
associationMappings
as
$assoc
Mapping
)
{
if
(
!
$assoc
Mapping
->
isCascadeRemove
)
{
foreach
(
$class
->
associationMappings
as
$assoc
)
{
if
(
!
$assoc
->
isCascadeRemove
)
{
continue
;
}
$relatedEntities
=
$class
->
reflFields
[
$assoc
Mapping
->
sourceFieldName
]
->
getValue
(
$entity
);
$relatedEntities
=
$class
->
reflFields
[
$assoc
->
sourceFieldName
]
->
getValue
(
$entity
);
if
(
$relatedEntities
instanceof
Collection
||
is_array
(
$relatedEntities
))
{
if
(
$relatedEntities
instanceof
PersistentCollection
)
{
// Unwrap so that foreach() does not initialize
$relatedEntities
=
$relatedEntities
->
unwrap
();
}
// If its a PersistentCollection initialization is intended! No unwrap!
foreach
(
$relatedEntities
as
$relatedEntity
)
{
$this
->
_doRemove
(
$relatedEntity
,
$visited
);
}
...
...
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
View file @
c3ef0195
...
...
@@ -475,4 +475,38 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertEquals
(
'Berlin'
,
$gblanco
->
getAddress
()
->
getCity
());
}
public
function
testOneToManyCascadeRemove
()
{
$user
=
new
CmsUser
;
$user
->
name
=
'Guilherme'
;
$user
->
username
=
'gblanco'
;
$user
->
status
=
'developer'
;
for
(
$i
=
0
;
$i
<
3
;
++
$i
)
{
$phone
=
new
CmsPhonenumber
;
$phone
->
phonenumber
=
100
+
$i
;
$user
->
addPhonenumber
(
$phone
);
}
$this
->
_em
->
persist
(
$user
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
$query
=
$this
->
_em
->
createQuery
(
"select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'"
);
$gblanco
=
$query
->
getSingleResult
();
$this
->
_em
->
remove
(
$gblanco
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
$this
->
assertEquals
(
0
,
$this
->
_em
->
createQuery
(
"select count(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p"
)
->
getSingleScalarResult
());
$this
->
assertEquals
(
0
,
$this
->
_em
->
createQuery
(
"select count(u.id) from Doctrine\Tests\Models\CMS\CmsUser u"
)
->
getSingleScalarResult
());
}
}
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