Skip to content

Commit

Permalink
Fix function IDENTITY() losing null type
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Dec 16, 2022
1 parent 1ecde5c commit cf2bc23
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Type/Doctrine/Query/QueryResultTypeWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ public function walkFunction($function)
}

$nullable = ($joinColumn['nullable'] ?? true)
|| $this->isQueryComponentNullable($dqlAlias)
|| $this->hasAggregateWithoutGroupBy();

$fieldType = $this->resolveDatabaseInternalType($typeName, $enumType, $nullable);
Expand Down
5 changes: 4 additions & 1 deletion tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
',
];

Expand Down
15 changes: 14 additions & 1 deletion tests/Type/Doctrine/data/QueryResult/Entities/One.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
*
Expand All @@ -58,4 +66,9 @@ class One
* @var Embedded
*/
public $embedded;

public function __construct()
{
$this->subOne = new SubOne();
}
}
23 changes: 23 additions & 0 deletions tests/Type/Doctrine/data/QueryResult/Entities/SubOne.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace QueryResult\Entities;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;

/**
* @Entity
*/
class SubOne
{
/**
* @GeneratedValue()
* @Column(type="integer")
* @Id
*
* @var string
*/
public $id;
}

0 comments on commit cf2bc23

Please sign in to comment.