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
49a24c4e
Commit
49a24c4e
authored
Sep 06, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Fixed #2478.
parent
d30e8143
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
35 deletions
+38
-35
PersistentCollection.php
lib/Doctrine/ORM/PersistentCollection.php
+2
-6
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+5
-7
StandardEntityPersisterTest.php
...rine/Tests/ORM/Functional/StandardEntityPersisterTest.php
+31
-22
No files found.
lib/Doctrine/ORM/PersistentCollection.php
View file @
49a24c4e
...
...
@@ -177,9 +177,7 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
*/
public
function
hydrateAdd
(
$element
)
{
if
(
!
$this
->
contains
(
$element
))
{
$this
->
_coll
->
add
(
$element
);
}
$this
->
_coll
->
add
(
$element
);
// If _backRefFieldName is set, then the association is bidirectional
// and we need to set the back reference.
...
...
@@ -206,9 +204,7 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
*/
public
function
hydrateSet
(
$key
,
$element
)
{
if
(
!
$this
->
contains
(
$element
))
{
$this
->
_coll
->
set
(
$key
,
$element
);
}
$this
->
_coll
->
set
(
$key
,
$element
);
// If _backRefFieldName is set, then the association is bidirectional
// and we need to set the back reference.
...
...
lib/Doctrine/ORM/UnitOfWork.php
View file @
49a24c4e
...
...
@@ -451,13 +451,10 @@ class UnitOfWork implements PropertyChangedListener
$actualData
[
$name
]
=
$refProp
->
getValue
(
$entity
);
}
if
(
$class
->
isCollectionValuedAssociation
(
$name
)
&&
$actualData
[
$name
]
!==
null
)
{
if
(
$class
->
isCollectionValuedAssociation
(
$name
)
&&
$actualData
[
$name
]
!==
null
&&
!
(
$actualData
[
$name
]
instanceof
PersistentCollection
))
{
// If $actualData[$name] is Collection then unwrap the array
if
(
!
$actualData
[
$name
]
instanceof
ArrayCollection
)
{
if
(
$actualData
[
$name
]
instanceof
PersistentCollection
)
{
$actualData
[
$name
]
=
$actualData
[
$name
]
->
toArray
();
}
$actualData
[
$name
]
=
new
ArrayCollection
(
$actualData
[
$name
]);
}
...
...
@@ -1136,8 +1133,9 @@ class UnitOfWork implements PropertyChangedListener
$visited
[
$oid
]
=
$entity
;
// Mark visited
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
$entityState
=
$this
->
getEntityState
(
$entity
,
self
::
STATE_NEW
);
$class
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$entity
));
$entityState
=
$this
->
getEntityState
(
$entity
,
self
::
STATE_NEW
);
switch
(
$entityState
)
{
case
self
::
STATE_MANAGED
:
// Nothing to do, except if policy is "deferred explicit"
...
...
tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php
View file @
49a24c4e
...
...
@@ -3,7 +3,7 @@
namespace
Doctrine\Tests\ORM\Functional
;
use
Doctrine\Tests\Models\ECommerce\ECommerceCart
,
Doctrine\Tests\Models\ECommerce\ECommerce
Category
,
Doctrine\Tests\Models\ECommerce\ECommerce
Feature
,
Doctrine\Tests\Models\ECommerce\ECommerceCustomer
,
Doctrine\Tests\Models\ECommerce\ECommerceProduct
;
...
...
@@ -48,31 +48,40 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/
public
function
testAddPersistRetrieve
()
{
$category
=
new
ECommerceCategory
();
$category
->
setName
(
'Eletronics'
);
$product
=
new
ECommerceProduct
();
$product
->
setName
(
'MP3 Player Foo'
);
$category
->
addProduct
(
$product
);
$product2
=
new
ECommerceProduct
();
$product2
->
setName
(
'MP3 Player Bar'
);
$category
->
addProduct
(
$product2
);
$this
->
_em
->
persist
(
$category
);
$f1
=
new
ECommerceFeature
;
$f1
->
setDescription
(
'AC-3'
);
$f2
=
new
ECommerceFeature
;
$f2
->
setDescription
(
'DTS'
);
$p
=
new
ECommerceProduct
;
$p
->
addFeature
(
$f1
);
$p
->
addfeature
(
$f2
);
$this
->
_em
->
persist
(
$p
);
$this
->
_em
->
flush
();
// He reported that using $this->_em->clear(); after flush fixes the problem.
// It should work out of the box. That's what we are testing.
$this
->
assertEquals
(
2
,
count
(
$p
->
getFeatures
()));
$this
->
assertTrue
(
$p
->
getFeatures
()
instanceof
\Doctrine\ORM\PersistentCollection
);
$q
=
$this
->
_em
->
createQuery
(
'SELECT p, f
FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p
JOIN p.features f'
);
$q
=
$this
->
_em
->
createQuery
(
'
SELECT c, p
FROM Doctrine\Tests\Models\ECommerce\ECommerceCategory c
LEFT JOIN c.products p
'
);
$res
=
$q
->
getResult
();
$this
->
assertEquals
(
1
,
count
(
$res
));
$this
->
assertEquals
(
2
,
count
(
$res
[
0
]
->
getProducts
()));
$this
->
assertEquals
(
2
,
count
(
$p
->
getFeatures
()));
$this
->
assertTrue
(
$p
->
getFeatures
()
instanceof
\Doctrine\ORM\PersistentCollection
);
// Check that the features are the same instances still
foreach
(
$p
->
getFeatures
()
as
$feature
)
{
if
(
$feature
->
getDescription
()
==
'AC-3'
)
{
$this
->
assertTrue
(
$feature
===
$f1
);
}
else
{
$this
->
assertTrue
(
$feature
===
$f2
);
}
}
}
}
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