title: Doctrine ManyToOne relationship - auto-remove on "set"
body: <p>I'm working with relationships in Doctrine (using Symfony 5).
  What I have is these 2 relations:</p>
  <ol>
  <li>User</li>
  <li>Availability</li>
  </ol>
  <p>User has an ID and has Many Availabilities.</p>
  <p>So Entity User has</p>
  <pre><code>/**
   * @ORM\OneToMany(targetEntity=&quot;UserAvailability&quot;, mappedBy=&quot;user&quot;)
   */
  private $availability;
  </code></pre>
  <p>and the reverse on Entity Availability.</p>
  <p>Availability is a relation with:</p>
  <p>id, user_id, day_name, start_time and end_time, that simple.</p>
  <p>What I already achieved with ManyToMany and I want to achieve in this case too is:</p>
  <p>I need to receive the entire set of availabilities for a User from the client and use it to update the availabilities of my User, so I defined a setAvailability method which receives a Collection of Availability entities and simply does</p>
  <p><code>$this-&gt;availabilities = $availabilities.</code></p>
  <p>This works when I add new availabilities but the ones that are on the DB and not in the collection are not dropped when I persist the entity.</p>
  <p>The same method works flawlessly with ManyToMany Relationship.</p>
  <p>What am I missing?</p>
  <p>*** UPDATE **</p>
  <pre><code>public function setAvailability($availability): self
      {
          $this-&gt;availability = $availability;
          return $this;
      }
  
  </code></pre>
  <p>this same code works when removing relations in ManyToMany relationship but not in ManyToOne, the attribute &quot;availability&quot; is correctly set, but when using persist/flush the availability which was removed is not removed on the DB.</p>
  <p>Thanks</p>