启用自动映射
此约束允许在类或属性上启用 Doctrine 的自动映射。自动映射允许基于 Doctrine 的属性确定验证规则。当全局禁用自动映射时,但您仍然希望为特定类或属性启用此功能时,可以使用此约束。
基本用法
在以下示例中,EnableAutoMapping 约束将告知验证器从 Doctrine 的元数据中收集约束。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// src/Model/BookCollection.php
namespace App\Model;
use App\Model\Author;
use App\Model\BookMetadata;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[Assert\EnableAutoMapping]
class BookCollection
{
#[ORM\Column(nullable: false)]
protected string $name = '';
#[ORM\ManyToOne(targetEntity: Author::class)]
public Author $author;
// ...
}
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可获得许可。