【发布时间】:2017-02-14 06:11:01
【问题描述】:
Symfony2 - UniqueEntity 不能与字段一起使用 ignoreNull
// src/AppBundle/Entity/Service.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @UniqueEntity(
* fields={"host", "port"},
* errorPath="port",
* message="This port is already in use on that host."
* )
*/
class Service
{
/**
* @ORM\ManyToOne(targetEntity="Host")
*/
public $host;
/**
* @ORM\Column(type="integer", nullable = true)
*/
public $port;
}
我尝试使用空值添加端口,它抛出“该端口已在该主机上使用。”错误。
我想在端口为空时忽略验证。
【问题讨论】:
标签: php validation symfony