Skip to content

Commit 1f1891d

Browse files
authored
Merge pull request #11926 from greg0ire/3.3.x
Merge 2.20.x up into 3.3.x
2 parents 0e3cff0 + c9fc4d9 commit 1f1891d

17 files changed

+208
-39
lines changed

docs/en/reference/association-mapping.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ Is essentially the same as following:
948948
<doctrine-mapping>
949949
<entity class="Product">
950950
<one-to-one field="shipment" target-entity="Shipment">
951-
<join-column name="shipment_id" referenced-column-name="id" nulable=false />
951+
<join-column name="shipment_id" referenced-column-name="id" nullable=false />
952952
</one-to-one>
953953
</entity>
954954
</doctrine-mapping>

docs/en/reference/events.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ specific to a particular entity class's lifecycle.
265265
<?xml version="1.0" encoding="UTF-8"?>
266266
267267
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
268-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
268+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
269269
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
270270
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
271271
<entity name="User">

docs/en/reference/second-level-cache.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ level cache region.
299299
300300
<?xml version="1.0" encoding="utf-8"?>
301301
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
302-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
302+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
303303
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
304304
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
305305
<entity name="Country">
@@ -351,7 +351,7 @@ It caches the primary keys of association and cache each element will be cached
351351
352352
<?xml version="1.0" encoding="utf-8"?>
353353
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
354-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
354+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
355355
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
356356
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
357357
<entity name="State">

docs/en/reference/working-with-associations.rst

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,35 @@ methods:
736736

737737
.. note::
738738

739-
There is a limitation on the compatibility of Criteria comparisons.
740-
You have to use scalar values only as the value in a comparison or
741-
the behaviour between different backends is not the same.
739+
Depending on whether the collection has already been loaded from the
740+
database or not, criteria matching may happen at the database/SQL level
741+
or on objects in memory. This may lead to different results and come
742+
surprising, for example when a code change in one place leads to a collection
743+
becoming initialized and, as a side effect, returning a different result
744+
or even breaking a ``matching()`` call somewhere else. Also, collection
745+
initialization state in practical use cases may differ from the one covered
746+
in unit tests.
747+
748+
Database level comparisons are based on scalar representations of the values
749+
stored in entity properties. The field names passed to expressions correspond
750+
to property names. Comparison and sorting may be affected by
751+
database-specific behavior. For example, MySQL enum types sort by index position,
752+
not lexicographically by value.
753+
754+
In-memory handling is based on the ``Selectable`` API of `Doctrine Collections <https://www.doctrine-project.org/projects/doctrine-collections/en/stable/index.html#matching>`.
755+
In this case, field names passed to expressions are being used to derive accessor
756+
method names. Strict type comparisons are used for equal and not-equal checks,
757+
and generally PHP language rules are being used for other comparison operators
758+
or sorting.
759+
760+
As a general guidance, for consistent results use the Criteria API with scalar
761+
values only. Note that ``DateTime`` and ``DateTimeImmutable`` are two predominant
762+
examples of value objects that are *not* scalars.
763+
764+
Refrain from using special database-level column types or custom Doctrine Types
765+
that may lead to database-specific comparison or sorting rules being applied, or
766+
to database-level values being different from object field values.
767+
768+
Provide accessor methods for all entity fields used in criteria expressions,
769+
and implement those methods in a way that their return value is the
770+
same as the database-level value.

docs/en/reference/xml-mapping.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ setup for the latest code in trunk.
1818
.. code-block:: xml
1919
2020
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
21-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2222
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
2323
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
2424
@@ -104,7 +104,7 @@ of several common elements:
104104
// Doctrine.Tests.ORM.Mapping.User.dcm.xml
105105
<?xml version="1.0" encoding="UTF-8"?>
106106
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
107-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
107+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
108108
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
109109
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
110110
@@ -770,7 +770,7 @@ entity relationship. You can define this in XML with the "association-key" attri
770770
.. code-block:: xml
771771
772772
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
773-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
773+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
774774
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
775775
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
776776

docs/en/tutorials/composite-primary-keys.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ and year of production as primary keys:
5454
5555
<?xml version="1.0" encoding="UTF-8"?>
5656
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
57-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
57+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5858
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
5959
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
6060
@@ -175,7 +175,7 @@ We keep up the example of an Article with arbitrary attributes, the mapping look
175175
.. code-block:: xml
176176
177177
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
178-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
178+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
179179
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
180180
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
181181

docs/en/tutorials/extra-lazy-associations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ switch to extra lazy as shown in these examples:
7171
7272
<?xml version="1.0" encoding="UTF-8"?>
7373
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
74-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
74+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7575
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
7676
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
7777

docs/en/tutorials/getting-started.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ methods, but you only need to choose one.
514514
515515
<!-- config/xml/Product.dcm.xml -->
516516
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
517-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
517+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
518518
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
519519
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
520520
@@ -1023,7 +1023,7 @@ the ``Product`` before:
10231023
10241024
<!-- config/xml/Bug.dcm.xml -->
10251025
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
1026-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
1026+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10271027
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
10281028
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
10291029
@@ -1103,7 +1103,7 @@ Finally, we'll add metadata mappings for the ``User`` entity.
11031103
11041104
<!-- config/xml/User.dcm.xml -->
11051105
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
1106-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
1106+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11071107
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
11081108
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
11091109
@@ -1586,7 +1586,7 @@ we have to adjust the metadata slightly.
15861586
.. code-block:: xml
15871587
15881588
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
1589-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
1589+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15901590
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
15911591
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
15921592

docs/en/tutorials/working-with-indexed-associations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ here are the code and mappings for it:
7878
7979
<?xml version="1.0" encoding="UTF-8"?>
8080
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
81-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
81+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8282
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
8383
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
8484

docs/en/tutorials/working-with-indexed-associations/market.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
3-
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
55
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
66

src/Proxy/ProxyFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private function createLazyInitializer(ClassMetadata $classMetadata, EntityPersi
233233
$class = $entityPersister->getClassMetadata();
234234

235235
foreach ($class->getReflectionProperties() as $property) {
236-
if (! $property || isset($identifier[$property->getName()]) || ! $class->hasField($property->getName()) && ! $class->hasAssociation($property->getName())) {
236+
if (! $property || isset($identifier[$property->getName()])) {
237237
continue;
238238
}
239239

@@ -262,7 +262,7 @@ private function getProxyFactory(string $className): Closure
262262
foreach ($reflector->getProperties($filter) as $property) {
263263
$name = $property->name;
264264

265-
if ($property->isStatic() || (($class->hasField($name) || $class->hasAssociation($name)) && ! isset($identifiers[$name]))) {
265+
if ($property->isStatic() || ! isset($identifiers[$name])) {
266266
continue;
267267
}
268268

src/UnitOfWork.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
use InvalidArgumentException;
5050
use RuntimeException;
5151
use Stringable;
52+
use Symfony\Component\VarExporter\Hydrator;
5253
use UnexpectedValueException;
5354

5455
use function array_chunk;
@@ -2379,6 +2380,8 @@ public function createEntity(string $className, array $data, array &$hints = [])
23792380

23802381
if ($this->isUninitializedObject($entity)) {
23812382
$entity->__setInitialized(true);
2383+
2384+
Hydrator::hydrate($entity, (array) $class->reflClass->newInstanceWithoutConstructor());
23822385
} else {
23832386
if (
23842387
! isset($hints[Query::HINT_REFRESH])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\GH11524;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
9+
#[ORM\Entity]
10+
#[ORM\Table(name: 'gh11524_entities')]
11+
class GH11524Entity
12+
{
13+
#[ORM\Id]
14+
#[ORM\Column(type: 'integer')]
15+
#[ORM\GeneratedValue]
16+
public int|null $id = null;
17+
18+
#[ORM\ManyToOne(targetEntity: GH11524Relation::class)]
19+
#[ORM\JoinColumn(name: 'relation_id', referencedColumnName: 'id', nullable: true)]
20+
public GH11524Relation|null $relation = null;
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\GH11524;
6+
7+
use Doctrine\ORM\Event\PostLoadEventArgs;
8+
9+
class GH11524Listener
10+
{
11+
public function postLoad(PostloadEventArgs $eventArgs): void
12+
{
13+
$object = $eventArgs->getObject();
14+
15+
if (! $object instanceof GH11524Relation) {
16+
return;
17+
}
18+
19+
$object->setCurrentLocale('en');
20+
}
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\GH11524;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
use LogicException;
9+
10+
#[ORM\Entity]
11+
#[ORM\Table(name: 'gh11524_relations')]
12+
class GH11524Relation
13+
{
14+
#[ORM\Id]
15+
#[ORM\Column(type: 'integer')]
16+
#[ORM\GeneratedValue]
17+
public int|null $id;
18+
19+
#[ORM\Column(type: 'string')]
20+
public string $name;
21+
22+
private string|null $currentLocale;
23+
24+
public function setCurrentLocale(string $locale): void
25+
{
26+
$this->currentLocale = $locale;
27+
}
28+
29+
public function getTranslation(): string
30+
{
31+
if ($this->currentLocale === null) {
32+
throw new LogicException('The current locale must be set to retrieve translation.');
33+
}
34+
35+
return 'fake';
36+
}
37+
}

0 commit comments

Comments
 (0)