2016-03-24 10 views
2

セッション参加を有するが、私は参加をチェックするセッション、およびすべてのでリストを作成しようとしています。symfonyはカスタムの多対多のチェックボックス

PersonInSessionテーブルはparticipants_idsession_idのテーブルを保持します。

私は次のエラーを取得しています:

Unable to transform value for property path "person": Expected a Doctrine\Common\Collections\Collection object.

私はセッションを作成し、直接同じ形式で参加者を確認したいです。

PersonEntityType

class PersonEntityType extends AbstractType 
{  
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('name'); 
    } 
} 

SessionEntityType

class SessionEntityType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('description') 
      ->add('participant', CollectionType::class, 
       array(
        'entry_type' => ParticipantEntityType::class, 
        'by_reference' => false, 
        'allow_add' => true, 
        'allow_delete' => true, 
       ) 
      ); 
    } 
} 

ParticipantEntityType

class ParticipantEntityType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('person', EntityType::class, 
       array(
        'class' => 'AppBundle:PersonEntity', 
        'choice_label' => 'name', 
        'expanded' =>'true', 
        'multiple' => 'true' 
       ) 
      ); 
    } 
} 

PersonEntity

class PersonEntity 
{ 
    private $id; 
    private $name; 

    /** 
    * @ORM\OneToMany(targetEntity="ParticipantEntity", mappedBy="person") 
    */ 
    private $participant; 

    public function __construct() 
    { 
     $this->participant = new ArrayCollection(); 
    } 
} 

SessionEntity

class SessionEntity 
{ 
    private $id; 
    private $description; 

    /** 
    * @ORM\OneToMany(targetEntity="ParticipantEntity", mappedBy="session") 
    */ 
    private $participant; 

    public function __construct() 
    { 
     $this->participant = new ArrayCollection(); 
    } 
} 

ParticipantEntityあなたが持っている必要があり

class ParticipantEntity 
{ 
    private $id; 

    /** 
    * @ORM\ManyToOne(targetEntity="PersonEntity", inversedBy="participant") 
    */ 
    private $person; 

    /** 
    * @ORM\ManyToOne(targetEntity="SessionEntity", inversedBy="participant") 
    */ 
    private $session; 

    public function __construct() 
    { 
     $this->person = new ArrayCollection(); 
    } 
} 
+0

** PersonEntity ** –

+0

のコードを表示してください。あなたは 'SessionEntity'と' ParticipantEntity'のコードも表示してください – Heah

答えて

0

namespace AppBundle\Entity; 

use Doctrine\Common\Collections\ArrayCollection 

class ParticipantEntity 
{ 
    // ... 

    /** 
    * @var PersonEntity[]|ArrayCollection 
    */ 
    private $person; 

    public function __construct() 
    { 
     $this->person = new ArrayCollection(); 
    } 

    // ... 

それ以外の場合は動作しません。

0

SessionEntityType、フィールド(participantsに変更したほうが意味があります)はCollectionTypeフィールドです。したがって、entry_typeParticipantEntityType)には、ターゲットエンティティ(ParticipantEntity)のコレクションプロパティにマップするフィールドを追加する必要があります。

このエンティティにはpersonがあり、participantとの間にはManyToOneの関係が間違っています。だから、それは以下のように定義する必要があります。

ParticipantEntity

class ParticipantEntity 
{ 
    /** 
    * @ORM\OneToMany(targetEntity="PersonEntity") 
    */ 
    private $persons; 

    public function __construct() 
    { 
     $this->person = new ArrayCollection(); 
    } 
} 

彼らは明らかに問題の源であると私は強く、あなたのエンティティを修正することをお勧めいたします。

関連する問題