8000 bug #31953 [DoctrineBridge] fix handling nested embeddables (xabbuh) · symfony/symfony@cf728f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf728f5

Browse files
committed
bug #31953 [DoctrineBridge] fix handling nested embeddables (xabbuh)
This PR was merged into the 4.3 branch. Discussion ---------- [DoctrineBridge] fix handling nested embeddables | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31911 | License | MIT | Doc PR | Commits ------- 37efa4b fix handling nested embeddables
2 parents 2b8e441 + 37efa4b commit cf728f5

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoctrineLoaderEmbed.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ class DoctrineLoaderEmbed
2222
* @ORM\Column(length=25)
2323
*/
2424
public $embeddedMaxLength;
25+
26+
/**
27+
* @ORM\Embedded(class=DoctrineLoaderNestedEmbed::class)
28+
*/
29+
public $nestedEmbedded;
2530
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping as ORM;
15+
16+
/**
17+
* @ORM\Embeddable()
18+
*/
19+
class DoctrineLoaderNestedEmbed
20+
{
21+
/**
22+
* @ORM\Column(length=27)
23+
*/
24+
public $nestedEmbeddedMaxLength;
25+
}

src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bridge\Doctrine\Tests\Fixtures\BaseUser;
1717
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderEmbed;
1818
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderEntity;
19+
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderNestedEmbed;
1920
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderParentEntity;
2021
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
2122
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
@@ -109,6 +110,20 @@ public function testLoadClassMetadata()
109110
$this->assertInstanceOf(Length::class, $embeddedMaxLengthConstraints[0]);
110111
$this->assertSame(25, $embeddedMaxLengthConstraints[0]->max);
111112

113+
$nestedEmbeddedMetadata = $embeddedClassMetadata->getPropertyMetadata('nestedEmbedded');
114+
$this->assertCount(1, $nestedEmbeddedMetadata);
115+
$this->assertSame(CascadingStrategy::CASCADE, $nestedEmbeddedMetadata[0]->getCascadingStrategy());
116+
$this->assertSame(TraversalStrategy::IMPLICIT, $nestedEmbeddedMetadata[0]->getTraversalStrategy());
117+
118+
$nestedEmbeddedClassMetadata = $validator->getMetadataFor(new DoctrineLoaderNestedEmbed());
119+
120+
$nestedEmbeddedMaxLengthMetadata = $nestedEmbeddedClassMetadata->getPropertyMetadata('nestedEmbeddedMaxLength');
121+
$this->assertCount(1, $nestedEmbeddedMaxLengthMetadata);
122+
$nestedEmbeddedMaxLengthConstraints = $nestedEmbeddedMaxLengthMetadata[0]->getConstraints();
123+
$this->assertCount(1, $nestedEmbeddedMaxLengthConstraints);
124+
$this->assertInstanceOf(Length::class, $nestedEmbeddedMaxLengthConstraints[0]);
125+
$this->assertSame(27, $nestedEmbeddedMaxLengthConstraints[0]->max);
126+
112127
$this->assertCount(0, $classMetadata->getPropertyMetadata('guidField'));
113128
$this->assertCount(0, $classMetadata->getPropertyMetadata('simpleArrayField'));
114129

src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
7979

8080
$constraint = $this->getLengthConstraint($metadata, $mapping['fieldName']);
8181
if (null === $constraint) {
82-
if (isset($mapping['originalClass'])) {
82+
if (isset($mapping['originalClass']) && false === strpos($mapping['declaredField'], '.')) {
8383
$metadata->addPropertyConstraint($mapping['declaredField'], new Valid());
8484
} elseif (property_exists($className, $mapping['fieldName'])) {
8585
$metadata->addPropertyConstraint($mapping['fieldName'], new Length(['max' => $mapping['length']]));

0 commit comments

Comments
 (0)
0