示例#1
0
 /**
  * @param $column
  *
  * @return Select
  */
 public function select($column)
 {
     $builder = new Select($this->driver);
     $this->lastQuery = $builder;
     $columns = is_array($column) ? $column : func_get_args();
     return $builder->select($columns);
 }
示例#2
0
 public function testInWithSelect()
 {
     $platform = $this->getMockForAbstractClass(Platform::class);
     $driver = $this->getMockForAbstractClass(Driver::class, [$platform]);
     $select = new Select($driver);
     $select->select('*');
     $select->from('table');
     $expr = new Expression();
     $this->assertEquals('c IN(SELECT * FROM table)', $expr->in('c', $select)->get());
 }
示例#3
0
 public function joinToQuery(Select $query, $leftAlias, $alias)
 {
     $joinTable = $this->getJoinTable();
     $query->leftJoin($leftAlias, $joinTable, $joinTable, (new Expression())->eq("{$leftAlias}.{$this->getForeignKey()}", "{$joinTable}.{$this->getJoinTableForeignKey()}"));
     $query->leftJoin($joinTable, $this->related->getTable(), $alias, (new Expression())->eq("{$joinTable}.{$this->getJoinTableTargetKey()}", "{$alias}.{$this->getTargetKey()}"));
 }
示例#4
0
 /**
  * @param Entity $entity
  * @param Select $query
  * @param array  $with
  * @param string $prefix
  *
  * @return Select
  */
 private function joinRelationsToQuery(Entity $entity, Select $query, array $with, $prefix = '')
 {
     if ($prefix === '') {
         $leftAlias = $this->alias ?: $entity->getTable();
     } else {
         $leftAlias = $prefix;
         $prefix .= '_';
     }
     foreach (array_filter($with, [$entity, 'hasRelation']) as $relationName) {
         $relation = $entity->getRelation($relationName);
         $relatedEntity = $relation->getEntity();
         $alias = $prefix . $relationName;
         $query->addSelect(array_map(function ($item) use($alias) {
             return "{$alias}.{$item} as {$alias}_{$item}";
         }, array_values($relatedEntity->getFieldNames())));
         $relation->joinToQuery($query, $leftAlias, $alias);
         $strippedWith = Utils::filterPrefixedElements($with, $relationName . '.', Utils::FILTER_REMOVE_PREFIX);
         $this->joinRelationsToQuery($relatedEntity, $query, $strippedWith, $alias);
     }
     return $query;
 }