I want to make the ManyToMany member of Entity as "not null"
So I tried two patterns.
1) Adding @Assert\\NotBlank()
/**
* Many Users have Many Groups.
* @Assert\NotBlank()
* @ORM\ManyToMany(targetEntity="PlaceCat", inversedBy="placeinfos")
* @ORM\JoinTable(name="placeinfos_placecats")
*/
private $placeCats;
2) adding required => true
in FormObject.
$formMapper
->add('placeCats',null,array('required' => true)
However, both are ignored.
Is it possible to set 'not null' restriction for ManyToMany Entity??
ManyToMany with "not null" means you want at least 1? Then you need another Assert:
/**
* @Assert\Count(
* min = "1",
* minMessage = "You have to select at least 1 item"
* )
*/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.