DisableAutoMapping
此约束允许在类或属性上禁用 Doctrine 的自动映射。自动映射允许根据 Doctrine 的属性确定验证规则。当全局启用自动映射时,但你仍然希望为特定类或属性禁用此功能时,可以使用此约束。
应用于 | 属性或方法 |
类 | DisableAutoMapping |
基本用法
在以下示例中,DisableAutoMapping 约束将告诉验证器不要从 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\DisableAutoMapping]
class BookCollection
{
#[ORM\Column(nullable: false)]
protected string $name = '';
#[ORM\ManyToOne(targetEntity: Author::class)]
public Author $author;
// ...
}
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可获得许可。