title: [symfony 4]Filter CollectionType
body: <p>I manage student enrollment with a student entity as well as an ActivityStudent entity.
  Students necessarily have a class. So for the inscription I made a CollectionType like This:</p>
  
  <p><em>RegistrationType.php</em></p>
  
  <pre><code>$builder
  -&gt;add('StudentsNonSubscribe', CollectionType::class, array(
      'entry_type' =&gt; StudentRegistrationType::class,
      'by_reference' =&gt; true
  ));
  </code></pre>
  
  <p><em>StudentRegistrationType.php</em></p>
  
  <pre><code>$builder
              -&gt;add('id', HiddenType::class)
  
              -&gt;add('barCode')
              -&gt;add('firstname')
              -&gt;add('name')
              -&gt;add('phone_number')
              -&gt;add('Activity', EntityType::class, array(
                  'class' =&gt; Activity::class,
                  'choice_label' =&gt; "name",
                  'expanded' =&gt; true,
                  'mapped' =&gt; false))
              -&gt;add('Departure', EntityType::class, array(
                  'class' =&gt; ActivityScanPlace::class,
                  'choice_label' =&gt; 'name',
                  'expanded' =&gt; true,
                  'mapped' =&gt; false
              ))
              -&gt;add('needEquipement', CheckboxType::class, array('required' =&gt; false, 'mapped' =&gt; false))
              -&gt;add('needLesson', CheckboxType::class, array('required' =&gt; false, 'mapped' =&gt; false))
              -&gt;add('save', SubmitType::class, array('label' =&gt; 'Save'))
                  ;
  </code></pre>
  
  <p>Here all the students are displayed and I will like limited to the students present in ActivityStudent.
  To better understand I will put the three important entities:
  <em>ActivityStudent.php</em></p>
  
  <pre><code>class ActivityStudent
  {
  /**
   * @var int
   *
   * @ORM\Column(name="id", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
  private $id;
  
  
  /**
   * @var needEquipement
   *
   * @ORM\Column(name="need_mequipement", type="boolean", nullable=true)
   */
  private $needEquipement;
  
  /**
   * @var needLesson
   *
   * @ORM\Column(name="need_lesson", type="boolean", nullable=true)
   */
  private $needLesson;
  
  /**
   * @var \ActivityScanPlace
   *
   * @ORM\ManyToOne(targetEntity="ActivityScanPlace")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="id_scan_place", referencedColumnName="id")
   * })
   */
  private $idScanPlace;
  
  /**
   * @var \Student
   *
   * @ORM\ManyToOne(targetEntity="Student")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="id_student", referencedColumnName="id")
   * })
   */
  private $idStudent;
  
  /**
   * @var \ActivityOccurence
   *
   * @ORM\ManyToOne(targetEntity="ActivityOccurence")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="id_activity_occurence", referencedColumnName="id")
   * })
   */
  private $idActivityOccurence;
  </code></pre>
  
  <p>}</p>
  
  <p><em>Student.php</em></p>
  
  <pre><code>class Student{
  
  /**
   * @var int
   *
   * @ORM\Column(name="id", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
  private $id;
  
  /**
   * @var int
   *
   * @ORM\Column(name="bar_code", type="string", nullable=false)
   */
  private $barCode;
  
  /**
   * @var \DateTime
   *
   * @ORM\Column(name="born_date", type="date", nullable=false)
   */
  private $bornDate;
  
  /**
   * @var string
   *
   * @ORM\Column(name="name", type="string", length=125, nullable=false)
   */
  private $name;
  
  /**
   * @var string
   *
   * @ORM\Column(name="firstname", type="string", length=125, nullable=false)
   */
  private $firstname;
  
  /**
   * @var bool
   *
   * @ORM\Column(name="sex", type="boolean", nullable=false)
   */
  private $sex;
  
  /**
   * @var string|null
   *
   * @ORM\Column(name="email", type="string", length=100, nullable=true)
   */
  private $email;
  
  /**
   * @var string|null
   *
   * @ORM\Column(name="phone_number", type="string", length=25, nullable=true)
   */
  private $phone_number;
  
  /**
   * @var \Address
   *
   * @ORM\ManyToOne(targetEntity="Address")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="id_address", referencedColumnName="id")
   * })
   */
  private $idAddress;
  
  /**
   * @var \Class
   *
   * @ORM\ManyToOne(targetEntity="Class_")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="id_class_", referencedColumnName="id")
   * })
   */
  private $idClass;
  
  /**
   * @var \Company
   *
   * @ORM\ManyToOne(targetEntity="Company")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="id_company", referencedColumnName="id")
   * })
   */
  private $idCompany;}
  </code></pre>
  
  <p><em>Class_.php</em></p>
  
  <pre><code>class Class_
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $id;
  
      /**
       * @var int
       *
       * @ORM\Column(name="level", type="integer", nullable=false)
       */
      private $level;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=25, nullable=false)
       */
      private $name;
  
      /**
       * @var \Day
       *
       * @ORM\ManyToOne(targetEntity="Day")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="id_day", referencedColumnName="id")
       * })
       */
      private $idDay;
  
      /**
       * @var \Teacher
       *
       * @ORM\ManyToOne(targetEntity="Teacher")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="id_teacher", referencedColumnName="id")
       * })
       */
      private $idTeacher;
  
      /**
       * @var \Student
       *
       * @ORM\OneToMany(targetEntity="Student", mappedBy="idClass", cascade="all")
       * @ORM\OrderBy({"name" = "ASC"})
       */
      private $students;
  
  
      public function __construct() {
          $this-&gt;students = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
  
  
      public function addStudent(Student $student)
      {
          $this-&gt;students[] = $student;
          $student-&gt;setIdClass($this-&gt;getId());
  
          return $this;
      }
  
      public function setStudents($students)
      {
          $this-&gt;students = $students;
      }
  }
  </code></pre>
  
  <p>just need a way to not show students who are in ActivityStudent and I have no idea how to do it from a CollectionType.
  If you have a complete answer or even a track I will gladly take it. Thank you in advance ! : D</p>