我要将Entity的ManyToMany成员设为“不为空”
所以我尝试了两种模式。
1)添加@Assert \ NotBlank()
/**
* Many Users have Many Groups.
* @Assert\NotBlank()
* @ORM\ManyToMany(targetEntity="PlaceCat", inversedBy="placeinfos")
* @ORM\JoinTable(name="placeinfos_placecats")
*/
private $placeCats;
2)在FormObject中添加required => true
。
$formMapper
->add('placeCats',null,array('required' => true)
但是,两者都将被忽略。
是否可以为ManyToMany实体设置'not null'限制?
答案 0 :(得分:0)
ManyToMany(不为空)表示您至少要1个?然后您需要另一个断言:
/**
* @Assert\Count(
* min = "1",
* minMessage = "You have to select at least 1 item"
* )
*/