Skip to content

Commit bf3ea1a

Browse files
authored
Merge pull request #3533 from neos/bugfix/enums-in-orm
BUGFIX: Pass through enum mapping to ORM
2 parents 495dcad + 9c94b1e commit bf3ea1a

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

Neos.Flow/Classes/Persistence/Doctrine/Mapping/Driver/FlowAnnotationDriver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,12 +1125,13 @@ protected function addColumnToMappingArray(ORM\Column $columnAnnotation, array $
11251125
$mapping['fieldName'] = $fieldName;
11261126
}
11271127

1128-
$mapping['type'] = ($columnAnnotation->type === 'string') ? null : $columnAnnotation->type;
1128+
$mapping['type'] = $columnAnnotation->type;
11291129
$mapping['scale'] = $columnAnnotation->scale;
11301130
$mapping['length'] = $columnAnnotation->length;
11311131
$mapping['unique'] = $columnAnnotation->unique;
11321132
$mapping['nullable'] = $columnAnnotation->nullable;
11331133
$mapping['precision'] = $columnAnnotation->precision;
1134+
$mapping['enumType'] = $columnAnnotation->enumType;
11341135

11351136
if ($columnAnnotation->options) {
11361137
$mapping['options'] = $columnAnnotation->options;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Neos\Flow\Tests\Functional\Persistence\FixturesPHP8;
4+
5+
enum EnumForAProperty: string
6+
{
7+
case IS_A = 'A;';
8+
case IS_B = 'B;';
9+
}

Neos.Flow/Tests/Functional/Persistence/FixturesPHP8/TestEntity.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class TestEntity
5353
#[ORM\Embedded(class: "Neos\Flow\Tests\Functional\Persistence\FixturesPHP8\TestEmbeddable")]
5454
protected TestEmbeddable $embedded;
5555

56+
#[ORM\Column(type: 'string', enumType: EnumForAProperty::class)]
57+
protected EnumForAProperty $enumForAProperty = EnumForAProperty::IS_A;
58+
5659
/**
5760
* Constructor
5861
*/
@@ -163,4 +166,14 @@ public function getEmbeddedValueObject(): TestEmbeddedValueObject
163166
{
164167
return $this->embeddedValueObject;
165168
}
169+
170+
public function getEnumForAProperty(): EnumForAProperty
171+
{
172+
return $this->enumForAProperty;
173+
}
174+
175+
public function setEnumForAProperty(EnumForAProperty $enumForAProperty): void
176+
{
177+
$this->enumForAProperty = $enumForAProperty;
178+
}
166179
}

Neos.Flow/Tests/Functional/Persistence/PersistenceTestPHP8.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Neos\Flow\Persistence\Doctrine\QueryResult;
1919
use Neos\Flow\Persistence\Exception;
2020
use Neos\Flow\Persistence\Exception\ObjectValidationFailedException;
21+
use Neos\Flow\Tests\Functional\Persistence\FixturesPHP8\EnumForAProperty;
22+
use Neos\Flow\Tests\Functional\Persistence\FixturesPHP8\TestEntity;
2123
use Neos\Flow\Tests\FunctionalTestCase;
2224
use Neos\Utility\ObjectAccess;
2325

@@ -721,6 +723,19 @@ public function hasUnpersistedChangesReturnsTrueAfterObjectUpdate()
721723
self::assertTrue($this->persistenceManager->hasUnpersistedChanges());
722724
}
723725

726+
public function enumPropertyCanBePersisted()
727+
{
728+
$testEntity = new TestEntity();
729+
$testEntity->setEnumForAProperty(EnumForAProperty::IS_B);
730+
$this->testEntityRepository->add($testEntity);
731+
$this->persistenceManager->persistAll();
732+
$this->persistenceManager->clearState();
733+
734+
/** @var FixturesPHP8\TestEntity $testEntity */
735+
$testEntity = $this->testEntityRepository->findAll()->getFirst();
736+
self::assertEquals(EnumForAProperty::IS_B, $testEntity->getEnumForAProperty());
737+
}
738+
724739
/**
725740
* Helper which inserts example data into the database.
726741
*

0 commit comments

Comments
 (0)