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
304e2286
Commit
304e2286
authored
Dec 07, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-199] Fixed.
parent
4e504413
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
17 deletions
+116
-17
ObjectHydrator.php
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
+16
-17
DDC199Test.php
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php
+100
-0
No files found.
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
View file @
304e2286
...
@@ -126,13 +126,12 @@ class ObjectHydrator extends AbstractHydrator
...
@@ -126,13 +126,12 @@ class ObjectHydrator extends AbstractHydrator
* @param object $entity The entity to which the collection belongs.
* @param object $entity The entity to which the collection belongs.
* @param string $name The name of the field on the entity that holds the collection.
* @param string $name The name of the field on the entity that holds the collection.
*/
*/
private
function
_initRelatedCollection
(
$entity
,
$
n
ame
)
private
function
_initRelatedCollection
(
$entity
,
$
class
,
$fieldN
ame
)
{
{
$oid
=
spl_object_hash
(
$entity
);
$oid
=
spl_object_hash
(
$entity
);
$class
=
$this
->
_ce
[
get_class
(
$entity
)];
$relation
=
$class
->
associationMappings
[
$fieldName
];
$relation
=
$class
->
associationMappings
[
$name
];
$value
=
$class
->
reflFields
[
$
n
ame
]
->
getValue
(
$entity
);
$value
=
$class
->
reflFields
[
$
fieldN
ame
]
->
getValue
(
$entity
);
if
(
$value
===
null
)
{
if
(
$value
===
null
)
{
$value
=
new
ArrayCollection
;
$value
=
new
ArrayCollection
;
}
}
...
@@ -144,18 +143,18 @@ class ObjectHydrator extends AbstractHydrator
...
@@ -144,18 +143,18 @@ class ObjectHydrator extends AbstractHydrator
$value
$value
);
);
$value
->
setOwner
(
$entity
,
$relation
);
$value
->
setOwner
(
$entity
,
$relation
);
$class
->
reflFields
[
$
n
ame
]
->
setValue
(
$entity
,
$value
);
$class
->
reflFields
[
$
fieldN
ame
]
->
setValue
(
$entity
,
$value
);
$this
->
_uow
->
setOriginalEntityProperty
(
$oid
,
$
n
ame
,
$value
);
$this
->
_uow
->
setOriginalEntityProperty
(
$oid
,
$
fieldN
ame
,
$value
);
$this
->
_initializedCollections
[
$oid
.
$
n
ame
]
=
$value
;
$this
->
_initializedCollections
[
$oid
.
$
fieldN
ame
]
=
$value
;
}
else
if
(
isset
(
$this
->
_hints
[
Query
::
HINT_REFRESH
]))
{
}
else
if
(
isset
(
$this
->
_hints
[
Query
::
HINT_REFRESH
]))
{
// Is already PersistentCollection, but REFRESH
// Is already PersistentCollection, but REFRESH
$value
->
clear
();
$value
->
clear
();
$value
->
setDirty
(
false
);
$value
->
setDirty
(
false
);
$value
->
setInitialized
(
true
);
$value
->
setInitialized
(
true
);
$this
->
_initializedCollections
[
$oid
.
$
n
ame
]
=
$value
;
$this
->
_initializedCollections
[
$oid
.
$
fieldN
ame
]
=
$value
;
}
else
{
}
else
{
// Is already PersistentCollection, and DONT REFRESH
// Is already PersistentCollection, and DONT REFRESH
$this
->
_existingCollections
[
$oid
.
$
n
ame
]
=
$value
;
$this
->
_existingCollections
[
$oid
.
$
fieldN
ame
]
=
$value
;
}
}
return
$value
;
return
$value
;
...
@@ -266,11 +265,11 @@ class ObjectHydrator extends AbstractHydrator
...
@@ -266,11 +265,11 @@ class ObjectHydrator extends AbstractHydrator
continue
;
continue
;
}
}
$parentClass
=
$this
->
_
rsm
->
aliasMap
[
$parentAlias
];
$parentClass
=
$this
->
_
ce
[
$this
->
_rsm
->
aliasMap
[
$parentAlias
]
];
$oid
=
spl_object_hash
(
$parentObject
);
$oid
=
spl_object_hash
(
$parentObject
);
$relationField
=
$this
->
_rsm
->
relationMap
[
$dqlAlias
];
$relationField
=
$this
->
_rsm
->
relationMap
[
$dqlAlias
];
$relation
=
$
this
->
_ce
[
$parentClass
]
->
associationMappings
[
$relationField
];
$relation
=
$
parentClass
->
associationMappings
[
$relationField
];
$reflField
=
$
this
->
_ce
[
$parentClass
]
->
reflFields
[
$relationField
];
$reflField
=
$
parentClass
->
reflFields
[
$relationField
];
// Check the type of the relation (many or single-valued)
// Check the type of the relation (many or single-valued)
if
(
!
$relation
->
isOneToOne
())
{
if
(
!
$relation
->
isOneToOne
())
{
...
@@ -280,7 +279,7 @@ class ObjectHydrator extends AbstractHydrator
...
@@ -280,7 +279,7 @@ class ObjectHydrator extends AbstractHydrator
if
(
isset
(
$this
->
_initializedCollections
[
$collKey
]))
{
if
(
isset
(
$this
->
_initializedCollections
[
$collKey
]))
{
$reflFieldValue
=
$this
->
_initializedCollections
[
$collKey
];
$reflFieldValue
=
$this
->
_initializedCollections
[
$collKey
];
}
else
if
(
!
isset
(
$this
->
_existingCollections
[
$collKey
]))
{
}
else
if
(
!
isset
(
$this
->
_existingCollections
[
$collKey
]))
{
$reflFieldValue
=
$this
->
_initRelatedCollection
(
$parentObject
,
$relationField
);
$reflFieldValue
=
$this
->
_initRelatedCollection
(
$parentObject
,
$
parentClass
,
$
relationField
);
}
}
$indexExists
=
isset
(
$this
->
_identifierMap
[
$dqlAlias
][
$id
[
$dqlAlias
]]);
$indexExists
=
isset
(
$this
->
_identifierMap
[
$dqlAlias
][
$id
[
$dqlAlias
]]);
...
@@ -304,11 +303,11 @@ class ObjectHydrator extends AbstractHydrator
...
@@ -304,11 +303,11 @@ class ObjectHydrator extends AbstractHydrator
if
(
$relation
->
isOwningSide
&&
isset
(
$this
->
_ce
[
$entityName
]
->
inverseMappings
[
$relation
->
sourceEntityName
][
$relationField
]))
{
if
(
$relation
->
isOwningSide
&&
isset
(
$this
->
_ce
[
$entityName
]
->
inverseMappings
[
$relation
->
sourceEntityName
][
$relationField
]))
{
$inverseFieldName
=
$this
->
_ce
[
$entityName
]
->
inverseMappings
[
$relation
->
sourceEntityName
][
$relationField
]
->
sourceFieldName
;
$inverseFieldName
=
$this
->
_ce
[
$entityName
]
->
inverseMappings
[
$relation
->
sourceEntityName
][
$relationField
]
->
sourceFieldName
;
if
(
!
isset
(
$this
->
_initializedCollections
[
spl_object_hash
(
$element
)
.
$inverseFieldName
]))
{
if
(
!
isset
(
$this
->
_initializedCollections
[
spl_object_hash
(
$element
)
.
$inverseFieldName
]))
{
$this
->
_initRelatedCollection
(
$element
,
$inverseFieldName
);
$this
->
_initRelatedCollection
(
$element
,
$
this
->
_ce
[
$entityName
],
$
inverseFieldName
);
}
}
}
else
if
(
$relation
->
mappedByFieldName
)
{
}
else
if
(
$relation
->
mappedByFieldName
)
{
if
(
!
isset
(
$this
->
_initializedCollections
[
spl_object_hash
(
$element
)
.
$relation
->
mappedByFieldName
]))
{
if
(
!
isset
(
$this
->
_initializedCollections
[
spl_object_hash
(
$element
)
.
$relation
->
mappedByFieldName
]))
{
$this
->
_initRelatedCollection
(
$element
,
$relation
->
mappedByFieldName
);
$this
->
_initRelatedCollection
(
$element
,
$
this
->
_ce
[
$entityName
],
$
relation
->
mappedByFieldName
);
}
}
}
}
}
}
...
@@ -351,12 +350,12 @@ class ObjectHydrator extends AbstractHydrator
...
@@ -351,12 +350,12 @@ class ObjectHydrator extends AbstractHydrator
if
(
$inverseAssoc
->
isOneToMany
())
{
if
(
$inverseAssoc
->
isOneToMany
())
{
// Only initialize reverse collection if it is not yet initialized.
// Only initialize reverse collection if it is not yet initialized.
if
(
!
isset
(
$this
->
_initializedCollections
[
spl_object_hash
(
$element
)
.
$inverseAssoc
->
sourceFieldName
]))
{
if
(
!
isset
(
$this
->
_initializedCollections
[
spl_object_hash
(
$element
)
.
$inverseAssoc
->
sourceFieldName
]))
{
$this
->
_initRelatedCollection
(
$element
,
$inverseAssoc
->
sourceFieldName
);
$this
->
_initRelatedCollection
(
$element
,
$
targetClass
,
$
inverseAssoc
->
sourceFieldName
);
}
}
}
else
{
}
else
{
$targetClass
->
reflFields
[
$inverseAssoc
->
sourceFieldName
]
->
setValue
(
$element
,
$parentObject
);
$targetClass
->
reflFields
[
$inverseAssoc
->
sourceFieldName
]
->
setValue
(
$element
,
$parentObject
);
}
}
}
else
if
(
$
this
->
_ce
[
$parentClass
]
===
$targetClass
&&
$relation
->
mappedByFieldName
)
{
}
else
if
(
$
parentClass
===
$targetClass
&&
$relation
->
mappedByFieldName
)
{
// Special case: bi-directional self-referencing one-one on the same class
// Special case: bi-directional self-referencing one-one on the same class
$targetClass
->
reflFields
[
$relationField
]
->
setValue
(
$element
,
$parentObject
);
$targetClass
->
reflFields
[
$relationField
]
->
setValue
(
$element
,
$parentObject
);
}
}
...
...
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php
0 → 100644
View file @
304e2286
<?php
namespace
Doctrine\Tests\ORM\Functional\Ticket
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
class
DDC199Test
extends
\Doctrine\Tests\OrmFunctionalTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_schemaTool
->
createSchema
(
array
(
$this
->
_em
->
getClassMetadata
(
__NAMESPACE__
.
'\DDC199ParentClass'
),
$this
->
_em
->
getClassMetadata
(
__NAMESPACE__
.
'\DDC199ChildClass'
),
$this
->
_em
->
getClassMetadata
(
__NAMESPACE__
.
'\DDC199RelatedClass'
)
));
}
public
function
testPolymorphicLoading
()
{
$child
=
new
DDC199ChildClass
;
$child
->
parentData
=
'parentData'
;
$child
->
childData
=
'childData'
;
$this
->
_em
->
persist
(
$child
);
$related1
=
new
DDC199RelatedClass
;
$related1
->
relatedData
=
'related1'
;
$related1
->
parent
=
$child
;
$this
->
_em
->
persist
(
$related1
);
$related2
=
new
DDC199RelatedClass
;
$related2
->
relatedData
=
'related2'
;
$related2
->
parent
=
$child
;
$this
->
_em
->
persist
(
$related2
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
$query
=
$this
->
_em
->
createQuery
(
'select e,r from Doctrine\Tests\ORM\Functional\Ticket\DDC199ParentClass e join e.relatedEntities r'
);
$result
=
$query
->
getResult
();
$this
->
assertEquals
(
1
,
count
(
$result
));
$this
->
assertTrue
(
$result
[
0
]
instanceof
DDC199ChildClass
);
$this
->
assertTrue
(
$result
[
0
]
->
relatedEntities
->
isInitialized
());
$this
->
assertEquals
(
2
,
$result
[
0
]
->
relatedEntities
->
count
());
$this
->
assertTrue
(
$result
[
0
]
->
relatedEntities
[
0
]
instanceof
DDC199RelatedClass
);
$this
->
assertTrue
(
$result
[
0
]
->
relatedEntities
[
1
]
instanceof
DDC199RelatedClass
);
}
}
/**
* @Entity @Table(name="ddc199_entities")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"parent" = "DDC199ParentClass", "child" = "DDC199ChildClass"})
*/
class
DDC199ParentClass
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public
$id
;
/**
* @Column(type="string")
*/
public
$parentData
;
/**
* @OneToMany(targetEntity="DDC199RelatedClass", mappedBy="parent")
*/
public
$relatedEntities
;
}
/** @Entity */
class
DDC199ChildClass
extends
DDC199ParentClass
{
/**
* @Column(type="string")
*/
public
$childData
;
}
/** @Entity @Table(name="ddcxxx_relatedclass") */
class
DDC199RelatedClass
{
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
public
$id
;
/** @Column(type="string") */
public
$relatedData
;
/**
* @ManyToOne(targetEntity="DDC199ParentClass")
* @JoinColumn(name="parent_id", referencedColumnName="id")
*/
public
$parent
;
}
\ No newline at end of file
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