title: Symfony 3.3 - Doctrine - Doctrine - Persisting with a join table
body: <p>I'm developing a website with the PHP framework Symfony 3.3 and the ORM Doctrine.</p>
  
  <p>I have users, and each user can offer services. A service can be offers by more than one user.</p>
  
  <p>Everything is working well, except when I want to persist a services list of a user. Nothing happens and I don't get any error. Can you see anything that is wrong in my code?</p>
  
  <p>My User class (part of it):</p>
  
  <pre><code> class User implements AdvancedUserInterface, \Serializable
   {
  
       public function __construct(){
          $this-&gt;services = new ArrayCollection(); // Services offered by the user
       }
  
       /**
       *  
       * @var Doctrine\Common\Collections\ArrayCollection $services
       * 
       * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Service", inversedBy="users")
       * @ORM\JoinTable(name="service_offer")
       * 
       */
  
      private $services;
  
      function getServices() {
          return $this-&gt;services;
      }
  
      function setServices(ArrayCollection $services) {
          $this-&gt;services = $services;
          return $this;
      }
  
  }
  </code></pre>
  
  <p>My Service class (part of it):</p>
  
  <pre><code>class Service
  {
  
      /**
       * @var integer
       *
       * @ORM\Column(name="id_service", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $idService;
  
      /**
      * @var \Doctrine\Common\Collections\ArrayCollection $users
      * 
      * @ManyToMany(targetEntity="AppBundle\Entity\User", mappedBy="services")
      * 
      **/
      private $users;
  }
  </code></pre>
  
  <p>In my controller, I have:</p>
  
  <pre><code>class ServiceOfferController extends Controller {
  /**
   *
   * @param EntityManagerInterface $em
   * 
   * 
   * @Route("/member/ServiceOffer", name="ServiceOffer")
   */
  public function serviceOfferAction(Request $request, EntityManagerInterface $em){
  
      //$user = $this-&gt;getUser();
      $form = $this-&gt;createForm(ServiceOfferType::class);
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted()){
          // Services ticked in the formular
          $services = $form-&gt;get('services')-&gt;getData();
  
          $user = $this-&gt;getUser();
  
          $user-&gt;setServices($services);
  
          print_r($user-&gt;getServices());
  
          // Persisting in the DB
          $em-&gt;persist($user);
          $em-&gt;flush();
      }
  
      return $this-&gt;render('serviceOffer.html.twig', array(
          'form' =&gt; $form-&gt;createView()
      ));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>"print_r($user->getServices());" returns me data, but nothing is persisting in the table service_offer. Any idea?</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: </p>
  
  <p>also tried with specifying the columns, like that:</p>
  
  <pre><code>/**
   *  
   * @var Doctrine\Common\Collections\ArrayCollection $services
   * 
   * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Service", inversedBy="users")
   * @ORM\JoinTable(name="service_offer",
   *   joinColumns={
   *     @ORM\JoinColumn(name="id_user", referencedColumnName="id_user", onDelete="CASCADE")
   *   },
   *   inverseJoinColumns={
   *     @ORM\JoinColumn(name="id_service", referencedColumnName="id_service", onDelete="CASCADE")
   *   }
   * )
   * 
   */
  private $services;
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>My service_offer MySQL table is:</p>
  
  <pre><code>CREATE TABLE `service_offer` (
  `id_service_offer` INT(11) NOT NULL AUTO_INCREMENT,
  `id_user` INT(11) NULL DEFAULT NULL,
  `id_service` INT(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id_service_offer`),
  INDEX `fk_service_idx` (`id_service`),
  INDEX `fk_user_idx` (`id_user`),
  CONSTRAINT `fk_service` FOREIGN KEY (`id_service`) REFERENCES `service` (`id_service`),
  CONSTRAINT `fk_user` FOREIGN KEY (`id_user`) REFERENCES `user` (`id_user`)
  )
  </code></pre>