/**
  * @inheritdoc
  */
 public function add($dqlPartName, $dqlPart, $append = false)
 {
     if ($this->isValidFromPart($dqlPartName, $dqlPart)) {
         $this->addFromExprToAliasMap($dqlPart);
     } elseif ($this->isValidJoinPart($dqlPartName, $dqlPart)) {
         $join = current($dqlPart);
         $this->validateJoinParent($join);
         $this->validateJoinAssociation($join);
         $this->addJoinExprToAliasMap($join);
     } elseif (in_array($dqlPartName, array('from', 'join'))) {
         throw new RuntimeException(sprintf("Trying to add incompatible expression to DQL part '%s' in QueryBuilder", $dqlPartName));
     }
     return parent::add($dqlPartName, $dqlPart, $append);
 }
 /**
  * Creates query builder for this entity joined with associated translation
  * entity and constrained to current locale of TranslatableListener if it
  * has been set. It also adds second join to translation entity constrained
  * to default locale of TranslatableListener if it has been set.
  *
  * @param string $alias
  * @param string $translationAlias
  * @param string $defaultTranslationAlias
  * @return \Doctrine\ORM\QueryBuilder
  */
 public function createTranslatableQueryBuilder($alias, $translationAlias = 't', $defaultTranslationAlias = 'dt')
 {
     $qb = new QueryBuilder($this->_em);
     $qb->select($alias)->from($this->_entityName, $alias);
     $translatableProperties = $this->getExtendedMetadata()->getTranslatableProperties();
     foreach ($translatableProperties as $translationAssociation => $properties) {
         $localeProperty = $this->getTranslationExtendedMetadata($translationAssociation)->localeProperty;
         $locale = $this->getTranslatableListener()->getLocale();
         if (isset($locale)) {
             $qb->leftJoin(sprintf('%s.%s', $alias, $translationAssociation), $translationAlias, Expr\Join::WITH, sprintf('%s.%s = :locale', $translationAlias, $localeProperty));
             $qb->addSelect($translationAlias);
             $qb->setParameter('locale', $locale);
         }
         $defaultLocale = $this->getTranslatableListener()->getDefaultLocale();
         if (isset($defaultLocale)) {
             $qb->leftJoin(sprintf('%s.%s', $alias, $translationAssociation), $defaultTranslationAlias, Expr\Join::WITH, sprintf('%s.%s = :deflocale', $defaultTranslationAlias, $localeProperty));
             $qb->addSelect($defaultTranslationAlias);
             $qb->setParameter('deflocale', $defaultLocale);
         }
     }
     return $qb;
 }