First of all, I assume that your user entity constructor looks something like this:
class User
{
public function __construct()
{
...
$this->tasks = new \Doctrine\Common\Collections\ArrayCollection();
...
}
}
If this is not the case so far, stop reading and correct me in the comments :)
Note that the ArrayCollection class was created by Doctrine. Symfony and most of its components do well in documenting classes. When you look at this class, you will find:
http://www.doctrine-project.org/api/common/2.2/class-Doctrine.Common.Collections.ArrayCollection.html
(, , , )
, ArrayCollection. : clear().
, User :
class User
{
public function clearTasks()
{
$this->getTasks()->clear();
}
}
User :
$user->clearTasks();
( !)