2016-11-28 6 views
0

私はformbuilderのチケットフィールドにcollectiontypeを使用しています。しかし、私はAssert検証を追加する間だけいくつかのエラーが発生しています。"string"、 "Doctrine ORM PersistentCollection"型の予想される引数があります

Entity 
/** 
* @Assert\Length(
*  min = 1, 
*  max = 10, 
*  minMessage = "Atlest one ticket to be added", 
*  maxMessage = "Not allowed" 
*) 
    * 
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\EventTicket", inversedBy="events", cascade={"persist"}) 
*/ 
public $tickets; 


Type 
public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 
    ->add('tickets', CollectionType::class, [ 
     'entry_type' => EventTicketType::class, 
     'allow_add' => true, 
     'allow_delete' => true 
    ]) 
} 

エラー:

答えて

3

@Assert\Length与えられた型 "string"、 "教義\ ORM \ PersistentCollection" の

予想される引数は、文字列の制約で、コレクション型のために使用することはできません。コレクションタイプには@Assert\Countを使用する必要があります。これは次のようになります。

/** 
* @Assert\Count(
*  min = 1, 
*  max = 10, 
*  minMessage = "At least one ticket to be added", 
*  maxMessage = "Not allowed" 
*) 
    * 
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\EventTicket", inversedBy="events", cascade={"persist"}) 
*/ 
public $tickets; 
関連する問題