2016-10-13 11 views
2

2つのエンティティBusPeopleの間に、関係がOneToManyであるとします。 バスには最大10人まで収容できます。max childを制限するための制約を作成する方法

これを制御するための制約を作成するにはどうすればよいですか?例えば

* @MyAssert\ParentMaxChild(max=10) 

* @ORM\ManyToOne(targetEntity="Webface\CharacterBundle\Entity\Bus", inversedBy="wac") 
* @ORM\JoinColumn(name="bus_id", referencedColumnName="id", nullable=false) 

private $bus; 

答えて

5

Count constraintを使用してください。あなたのBusクラスで

、人の注釈に制約を追加:あなたはminパラメータとに従ってメッセージを指定することができます

/** 
* ... Rest of the annotation ... 
* @Assert\Count(
*  max = "10", 
*  maxMessage = "Bus can hold a maximum of 10 persons." 
*) 
*/ 
protected $persons; 

注意を。

関連する問題