I have a Command
entity which has a n:m relationship with Alias
. This is a piece of code of the Command
class:
class Command
{
...
/**
* @ORM\ManyToMany(targetEntity="Alias", inversedBy="alias_command", cascade={"persist", "remove"})
* @ORM\JoinTable(name="command_has_alias",
* joinColumns={@ORM\JoinColumn(name="command_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="alias_id", referencedColumnName="id")}
* )
*/
protected $command_alias;
public function __construct()
{
$this->command_alias = new ArrayCollection();
}
...
/**
* Add alias to command.
* @param Alias $alias
*/
public function addCommandAlias(Alias $alias)
{
$this->command_alias[] = $alias;
}
/**
* Get alias from command.
* @return Doctrine\Common\Collections\Collection
*/
public function getCommandAlias()
{
return $this->command_alias;
}
/**
* Remove alias from command.
* @param Alias $alias
*/
public function removeCommandAlias(Alias $alias)
{
$this->command_alias->removeElement($alias);
return $this;
}
}
I want to delete an element from the collection (association in n:m intermediary table) but what I have is the ID of the Alias
. I read Doctrine docs around Removing associations but is not clear to me how to delete the element from the collection. I don't know if remove by key is the path to follow here or if I can do something in my entity to get this easy anyway I will not remove the Command
and either the Alias
I just want to remove the relation between them. Any advice?