/**
  * Converts EntityQuery to IExpresion object.
  *
  * Note that projections, and references to associated entities are useless and won't be
  * presented in the resulting expression because required joins can only be specified
  * as sources for selection
  *
  * @todo check whether we refer to encapsulants and avoid this
  *
  * @return IExpression
  */
 function toExpression()
 {
     if (!$this->condition) {
         return new ExpressionChain();
     }
     $eqb = new EntityQueryBuilder($this->entity);
     $subjected = $this->condition->toSubjected($eqb);
     Assert::isTrue(sizeof($eqb->getSelectQuerySources()) == 1, 'do not refer to %s encapsulants here', $this->entity->getLogicalSchema()->getEntityName());
     return $subjected;
 }
 function fill(SelectQuery $selectQuery, EntityQuery $entityQuery)
 {
     $selectQuery->having($this->expression->toSubjected($entityQuery));
 }
 function fill(SelectQuery $selectQuery, EntityQueryBuilder $builder)
 {
     $selectQuery->setHaving($this->expression->toSubjected($builder));
 }