Can I check if an association exists before issuing a request in Doctrine2? Example:
class Product
{
public $features;
}
I would like to check (practically without issuing the request itself) that there is an association product.features.
EDIT : out of curiosity, I am writing a service (helper, really) to do some filtering of the collection based on GET parameters:
public function initialize($entityName, $key)
{
$this->values = array();
$this->collection = new ArrayCollection();
if(is_null($value = $this->request->get($key))
|| strlen(trim($value)) == 0) return $this;
$re = '/\s*' . $this->separator . '\s*/';
if(!($set = preg_split($re, $value, 0, PREG_SPLIT_NO_EMPTY))) return $this;
$guesser = $this->getManagementGuesser();
$repoName = $guesser->guessRepositoryName();
$entityName = $guesser->guessEntityName();
$qb = $this->getRepository($repoName)->createQueryBuilder('e');
$exists = $this->getEntitiesUtility()->checkRelation($entityName, $key);
if(!$exists) throw new \LogicException("Relation named '$key' not found.");
}
The relative part will be:
$this->getEntitiesUtility()->checkRelation($entityName, $relationName);
source
share