Skip to content

Commit 92e54ac

Browse files
llupafabpot
authored andcommitted
[PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type
1 parent ac07f3e commit 92e54ac

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\PropertyInfo;
1313

1414
use Doctrine\Common\Collections\Collection;
15+
use Doctrine\DBAL\Types\BigIntType;
1516
use Doctrine\DBAL\Types\Types;
1617
use Doctrine\ORM\EntityManagerInterface;
1718
use Doctrine\ORM\Mapping\AssociationMapping;
@@ -142,6 +143,15 @@ public function getTypes(string $class, string $property, array $context = [])
142143
}
143144

144145
$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);
146+
147+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
148+
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
149+
return [
150+
new Type(Type::BUILTIN_TYPE_INT, $nullable),
151+
new Type(Type::BUILTIN_TYPE_STRING, $nullable),
152+
];
153+
}
154+
145155
$enumType = null;
146156
if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) {
147157
$enumType = new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $enumClass);

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\Common\EventManager;
1717
use Doctrine\DBAL\DriverManager;
1818
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
19+
use Doctrine\DBAL\Types\BigIntType;
1920
use Doctrine\DBAL\Types\Type as DBALType;
2021
use Doctrine\ORM\EntityManager;
2122
use Doctrine\ORM\Mapping\Column;
@@ -162,10 +163,17 @@ public function testExtractEnum()
162163

163164
public static function typesProvider(): array
164165
{
166+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
167+
if (!method_exists(BigIntType::class, 'getName')) {
168+
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)];
169+
} else {
170+
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_STRING)];
171+
}
172+
165173
return [
166174
['id', [new Type(Type::BUILTIN_TYPE_INT)]],
167175
['guid', [new Type(Type::BUILTIN_TYPE_STRING)]],
168-
['bigint', [new Type(Type::BUILTIN_TYPE_STRING)]],
176+
['bigint', $expectedBingIntType],
169177
['time', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')]],
170178
['timeImmutable', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeImmutable')]],
171179
['dateInterval', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateInterval')]],

0 commit comments

Comments
 (0)