Skip to content

Commit cf2bc23

Browse files
Fix function IDENTITY() losing null type
1 parent 1ecde5c commit cf2bc23

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/Type/Doctrine/Query/QueryResultTypeWalker.php

+1
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ public function walkFunction($function)
550550
}
551551

552552
$nullable = ($joinColumn['nullable'] ?? true)
553+
|| $this->isQueryComponentNullable($dqlAlias)
553554
|| $this->hasAggregateWithoutGroupBy();
554555

555556
$fieldType = $this->resolveDatabaseInternalType($typeName, $enumType, $nullable);

tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ public function getTestData(): iterable
13771377
[new ConstantIntegerType(6), TypeCombinator::addNull($this->numericStringOrInt())],
13781378
[new ConstantIntegerType(7), TypeCombinator::addNull(new MixedType())],
13791379
[new ConstantIntegerType(8), TypeCombinator::addNull($this->numericStringOrInt())],
1380+
[new ConstantIntegerType(9), TypeCombinator::addNull($this->numericStringOrInt())],
13801381
]),
13811382
'
13821383
SELECT IDENTITY(m.oneNull),
@@ -1386,8 +1387,10 @@ public function getTestData(): iterable
13861387
IDENTITY(m.compoundPk, \'id\'),
13871388
IDENTITY(m.compoundPk, \'version\'),
13881389
IDENTITY(m.compoundPkAssoc),
1389-
IDENTITY(m.compoundPkAssoc, \'version\')
1390+
IDENTITY(m.compoundPkAssoc, \'version\'),
1391+
IDENTITY(o.subOne)
13901392
FROM QueryResult\Entities\Many m
1393+
LEFT JOIN m.oneNull o
13911394
',
13921395
];
13931396

tests/Type/Doctrine/data/QueryResult/Entities/One.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Doctrine\ORM\Mapping\Entity;
99
use Doctrine\ORM\Mapping\Id;
1010
use Doctrine\ORM\Mapping\JoinColumn;
11-
use Doctrine\ORM\Mapping\ManyToOne;
1211
use Doctrine\ORM\Mapping\OneToMany;
12+
use Doctrine\ORM\Mapping\OneToOne;
1313

1414
/**
1515
* @Entity
@@ -45,6 +45,14 @@ class One
4545
*/
4646
public $stringNullColumn;
4747

48+
/**
49+
* @OneToOne(targetEntity="QueryResult\Entities\SubOne", cascade={"persist"})
50+
* @JoinColumn(nullable=false)
51+
*
52+
* @var SubOne
53+
*/
54+
public $subOne;
55+
4856
/**
4957
* @OneToMany(targetEntity="QueryResult\Entities\Many", mappedBy="one")
5058
*
@@ -58,4 +66,9 @@ class One
5866
* @var Embedded
5967
*/
6068
public $embedded;
69+
70+
public function __construct()
71+
{
72+
$this->subOne = new SubOne();
73+
}
6174
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace QueryResult\Entities;
4+
5+
use Doctrine\ORM\Mapping\Column;
6+
use Doctrine\ORM\Mapping\Entity;
7+
use Doctrine\ORM\Mapping\Id;
8+
use Doctrine\ORM\Mapping\GeneratedValue;
9+
10+
/**
11+
* @Entity
12+
*/
13+
class SubOne
14+
{
15+
/**
16+
* @GeneratedValue()
17+
* @Column(type="integer")
18+
* @Id
19+
*
20+
* @var string
21+
*/
22+
public $id;
23+
}

0 commit comments

Comments
 (0)