|
| 1 | +DisableAutoMapping |
| 2 | +================== |
| 3 | + |
| 4 | +This constraint allows to disable :ref:`Doctrine's auto mapping <doctrine_auto-mapping>` |
| 5 | +on a class or a property. Automapping allows to determine validation rules based |
| 6 | +on Doctrine's annotations and attributes. You may use this constraint when |
| 7 | +automapping is globally enabled, but you still want to disable this feature for |
| 8 | +a class or a property specifically. |
| 9 | + |
| 10 | +========== =================================================================== |
| 11 | +Applies to :ref:`property or method <validation-property-target>` |
| 12 | +Class :class:`Symfony\\Component\\Validator\\Constraints\\DisableAutoMapping` |
| 13 | +========== =================================================================== |
| 14 | + |
| 15 | +Basic Usage |
| 16 | +----------- |
| 17 | + |
| 18 | +In the following example, the |
| 19 | +:class:`Symfony\\Component\\Validator\\Constraints\\DisableAutoMapping` |
| 20 | +constraint will tell the validator to not gather constraints from Doctrine's |
| 21 | +metadata: |
| 22 | + |
| 23 | +.. configuration-block:: |
| 24 | + |
| 25 | + .. code-block:: php-attributes |
| 26 | +
|
| 27 | + // src/Model/BookCollection.php |
| 28 | + namespace App\Model; |
| 29 | +
|
| 30 | + use App\Model\Author; |
| 31 | + use App\Model\BookMetadata; |
| 32 | + use Doctrine\ORM\Mapping as ORM; |
| 33 | + use Symfony\Component\Validator\Constraints as Assert; |
| 34 | +
|
| 35 | + #[Assert\DisableAutoMapping] |
| 36 | + class BookCollection |
| 37 | + { |
| 38 | + #[ORM\Column(nullable: false)] |
| 39 | + protected string $name = ''; |
| 40 | +
|
| 41 | + #[ORM\ManyToOne(targetEntity: Author::class)] |
| 42 | + public Author $author; |
| 43 | +
|
| 44 | + // ... |
| 45 | + } |
| 46 | +
|
| 47 | + .. code-block:: yaml |
| 48 | +
|
| 49 | + # config/validator/validation.yaml |
| 50 | + App\Entity\BookCollection: |
| 51 | + constraints: |
| 52 | + - DisableAutoMapping: ~ |
| 53 | +
|
| 54 | + .. code-block:: xml |
| 55 | +
|
| 56 | + <!-- config/validator/validation.xml --> |
| 57 | + <?xml version="1.0" encoding="UTF-8" ?> |
| 58 | + <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" |
| 59 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 60 | + xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> |
| 61 | +
|
| 62 | + <class name="App\Entity\BookCollection"> |
| 63 | + <constraint name="DisableAutoMapping"/> |
| 64 | + </class> |
| 65 | + </constraint-mapping> |
| 66 | +
|
| 67 | + .. code-block:: php |
| 68 | +
|
| 69 | + // src/Entity/BookCollection.php |
| 70 | + namespace App\Entity; |
| 71 | +
|
| 72 | + use Symfony\Component\Validator\Constraints as Assert; |
| 73 | + use Symfony\Component\Validator\Mapping\ClassMetadata; |
| 74 | +
|
| 75 | + class BookCollection |
| 76 | + { |
| 77 | + // ... |
| 78 | +
|
| 79 | + public static function loadValidatorMetadata(ClassMetadata $metadata) |
| 80 | + { |
| 81 | + $metadata->addConstraint(new Assert\DisableAutoMapping()); |
| 82 | + } |
| 83 | + } |
| 84 | +
|
| 85 | +Options |
| 86 | +------- |
| 87 | + |
| 88 | +The ``groups`` option is not available for this constraint. |
| 89 | + |
| 90 | +.. include:: /reference/constraints/_payload-option.rst.inc |
0 commit comments