Skip to content

Commit 7c956d8

Browse files
committed
minor symfony#54974 [DoctrineBridge] fix bigint handling with DBAL 4 (xabbuh)
This PR was merged into the 7.1 branch. Discussion ---------- [DoctrineBridge] fix bigint handling with DBAL 4 | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- a289973 fix bigint handling with DBAL 4
2 parents 232d6d0 + a289973 commit 7c956d8

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ public function getType(string $class, string $property, array $context = []): ?
130130
}
131131

132132
$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);
133+
134+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
135+
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
136+
return Type::collection(Type::int(), Type::string());
137+
}
138+
133139
$enumType = null;
134140

135141
if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) {
@@ -241,8 +247,8 @@ public function getTypes(string $class, string $property, array $context = []):
241247
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
242248
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
243249
return [
244-
new Type(Type::BUILTIN_TYPE_INT, $nullable),
245-
new Type(Type::BUILTIN_TYPE_STRING, $nullable),
250+
new LegacyType(LegacyType::BUILTIN_TYPE_INT, $nullable),
251+
new LegacyType(LegacyType::BUILTIN_TYPE_STRING, $nullable),
246252
];
247253
}
248254

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static function legacyTypesProvider(): array
156156
{
157157
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
158158
if (!method_exists(BigIntType::class, 'getName')) {
159-
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new Type(LegacyType::BUILTIN_TYPE_STRING)];
159+
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
160160
} else {
161161
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
162162
}
@@ -298,9 +298,16 @@ public function testExtract(string $property, ?Type $type)
298298
*/
299299
public static function typeProvider(): iterable
300300
{
301+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
302+
if (!method_exists(BigIntType::class, 'getName')) {
303+
$expectedBigIntType = Type::collection(Type::int(), Type::string());
304+
} else {
305+
$expectedBigIntType = Type::string();
306+
}
307+
301308
yield ['id', Type::int()];
302309
yield ['guid', Type::string()];
303-
yield ['bigint', Type::string()];
310+
yield ['bigint', $expectedBigIntType];
304311
yield ['time', Type::object(\DateTime::class)];
305312
yield ['timeImmutable', Type::object(\DateTimeImmutable::class)];
306313
yield ['dateInterval', Type::object(\DateInterval::class)];

0 commit comments

Comments
 (0)