11
I can't seem to find any mention in the Doctrine documentation on how to check if an entity has an existing relationship to another entity:
http://www.doctrine-project.org/docs/orm/2.0/en/reference/working-with-associations.html
In Doctrine 1.x there was a method called exists that could be called on an entity to check this:
In Doctrine 2.0 this is what I've tended to do. What techniques are other people using?
<?php
class Group {
private $id;
protected $name;
protected $users;
public function __construct()
{
$this->colorgroups = new ArrayCollection();
}
public function hasUsers() {
return count($this->users) > 0;
}
}