From a997fabd719be1060ec0b4a5794abac070439cb7 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 19 Nov 2022 14:28:27 +0100 Subject: [PATCH 1/2] Add failing test --- .../Query/QueryResultTypeWalkerTest.php | 5 +++- .../data/QueryResult/Entities/One.php | 15 +++++++++++- .../data/QueryResult/Entities/SubOne.php | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/Type/Doctrine/data/QueryResult/Entities/SubOne.php diff --git a/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php b/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php index 499a0732..31b99c8e 100644 --- a/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php +++ b/tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php @@ -1377,6 +1377,7 @@ public function getTestData(): iterable [new ConstantIntegerType(6), TypeCombinator::addNull($this->numericStringOrInt())], [new ConstantIntegerType(7), TypeCombinator::addNull(new MixedType())], [new ConstantIntegerType(8), TypeCombinator::addNull($this->numericStringOrInt())], + [new ConstantIntegerType(9), TypeCombinator::addNull($this->numericStringOrInt())], ]), ' SELECT IDENTITY(m.oneNull), @@ -1386,8 +1387,10 @@ public function getTestData(): iterable IDENTITY(m.compoundPk, \'id\'), IDENTITY(m.compoundPk, \'version\'), IDENTITY(m.compoundPkAssoc), - IDENTITY(m.compoundPkAssoc, \'version\') + IDENTITY(m.compoundPkAssoc, \'version\'), + IDENTITY(o.subOne) FROM QueryResult\Entities\Many m + LEFT JOIN m.oneNull o ', ]; diff --git a/tests/Type/Doctrine/data/QueryResult/Entities/One.php b/tests/Type/Doctrine/data/QueryResult/Entities/One.php index f6ef5b10..5605c945 100644 --- a/tests/Type/Doctrine/data/QueryResult/Entities/One.php +++ b/tests/Type/Doctrine/data/QueryResult/Entities/One.php @@ -8,8 +8,8 @@ use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\JoinColumn; -use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\OneToMany; +use Doctrine\ORM\Mapping\OneToOne; /** * @Entity @@ -45,6 +45,14 @@ class One */ public $stringNullColumn; + /** + * @OneToOne(targetEntity="QueryResult\Entities\SubOne", cascade={"persist"}) + * @JoinColumn(nullable=false) + * + * @var SubOne + */ + public $subOne; + /** * @OneToMany(targetEntity="QueryResult\Entities\Many", mappedBy="one") * @@ -58,4 +66,9 @@ class One * @var Embedded */ public $embedded; + + public function __construct() + { + $this->subOne = new SubOne(); + } } diff --git a/tests/Type/Doctrine/data/QueryResult/Entities/SubOne.php b/tests/Type/Doctrine/data/QueryResult/Entities/SubOne.php new file mode 100644 index 00000000..db7114aa --- /dev/null +++ b/tests/Type/Doctrine/data/QueryResult/Entities/SubOne.php @@ -0,0 +1,23 @@ + Date: Fri, 9 Dec 2022 14:14:56 +0100 Subject: [PATCH 2/2] Fix the test --- src/Type/Doctrine/Query/QueryResultTypeWalker.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Type/Doctrine/Query/QueryResultTypeWalker.php b/src/Type/Doctrine/Query/QueryResultTypeWalker.php index 1f592e42..30207634 100644 --- a/src/Type/Doctrine/Query/QueryResultTypeWalker.php +++ b/src/Type/Doctrine/Query/QueryResultTypeWalker.php @@ -550,6 +550,7 @@ public function walkFunction($function) } $nullable = ($joinColumn['nullable'] ?? true) + || $this->isQueryComponentNullable($dqlAlias) || $this->hasAggregateWithoutGroupBy(); $fieldType = $this->resolveDatabaseInternalType($typeName, $enumType, $nullable);