/**
  * @return SQLChain
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     $size = count($this->chain);
     Assert::isTrue($size > 0, 'empty chain');
     $chain = new $this();
     for ($i = 0; $i < $size; ++$i) {
         $chain->exp($dao->guessAtom($this->chain[$i], $query), $this->logic[$i]);
     }
     return $chain;
 }
 /**
  * @return InExpression
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     if (is_array($this->right)) {
         $right = array();
         foreach ($this->right as $atom) {
             $right[] = $dao->guessAtom($atom, $query);
         }
     } elseif ($this->right instanceof MappableObject) {
         $right = $this->right->toMapped($dao, $query);
     } else {
         $right = $this->right;
     }
     // untransformable
     return new self($dao->guessAtom($this->left, $query), $right, $this->logic);
 }
 /**
  * @return PrefixUnaryExpression
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     return new self($this->logic, $dao->guessAtom($this->subject, $query));
 }
 /**
  * @return LogicalBetween
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     return new self($dao->guessAtom($this->field, $query), $dao->guessAtom($this->left, $query), $dao->guessAtom($this->right, $query));
 }
 /**
  * @return FullText
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     return new $this($dao->guessAtom($this->field, $query, $dao->getTable()), $this->words, $this->logic);
 }
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     return new self($dao->guessAtom($this->range, $query), $dao->guessAtom($this->ip, $query));
 }
 /**
  * @return ExtractPart
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     return self::create($this->what, $dao->guessAtom($this->from, $query));
 }
 /**
  * @return PostfixUnaryExpression
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     $expression = new self($dao->guessAtom($this->subject, $query), $this->logic);
     return $expression->noBrackets(!$this->brackets);
 }
 private function joinProperties(SelectQuery $query, ProtoDAO $parentDao, $parentTable, $parentRequired, $prefix = null)
 {
     $proto = call_user_func(array($parentDao->getObjectName(), 'proto'));
     foreach ($proto->getPropertyList() as $property) {
         if ($property instanceof LightMetaProperty && $property->getRelationId() == MetaRelation::ONE_TO_ONE && !$property->isGenericType() && (!$property->getFetchStrategyId() && $this->getFetchStrategy()->getId() == FetchStrategy::JOIN || $property->getFetchStrategyId() == FetchStrategy::JOIN)) {
             if (is_subclass_of($property->getClassName(), 'Enumeration')) {
                 // field already added by makeSelectHead
                 continue;
             } elseif ($property->isInner()) {
                 $proto = call_user_func(array($property->getClassName(), 'proto'));
                 foreach ($proto->getPropertyList() as $innerProperty) {
                     $query->get(new DBField($innerProperty->getColumnName(), $parentTable));
                 }
                 continue;
             }
             $propertyDao = call_user_func(array($property->getClassName(), 'dao'));
             // add's custom dao's injection possibility
             if (!$propertyDao instanceof ProtoDAO) {
                 continue;
             }
             $tableAlias = $propertyDao->getJoinName($property->getColumnName(), $prefix);
             $fields = $propertyDao->getFields();
             if (!$query->hasJoinedTable($tableAlias)) {
                 $logic = Expression::eq(DBField::create($property->getColumnName(), $parentTable), DBField::create($propertyDao->getIdName(), $tableAlias));
                 if ($property->isRequired() && $parentRequired) {
                     $query->join($propertyDao->getTable(), $logic, $tableAlias);
                 } else {
                     $query->leftJoin($propertyDao->getTable(), $logic, $tableAlias);
                 }
             }
             foreach ($fields as $field) {
                 $query->get(new DBField($field, $tableAlias), $propertyDao->getJoinPrefix($property->getColumnName(), $prefix) . $field);
             }
             $this->joinProperties($query, $propertyDao, $tableAlias, $property->isRequired() && $parentRequired, $propertyDao->getJoinPrefix($property->getColumnName(), $prefix));
         }
     }
 }
 /**
  * @return OrderBy
  **/
 public function toMapped(ProtoDAO $dao, JoinCapableQuery $query)
 {
     $order = self::create($dao->guessAtom($this->field, $query));
     if (!$this->nulls->isNull()) {
         $order->setNullsFirst($this->nulls->getValue());
     }
     if (!$this->direction->isNull()) {
         $order->setDirection($this->direction->getValue());
     }
     return $order;
 }