/** * Transforms orm condition and adds it to QueryBuilder. * @param string $expression * @param mixed $value * @param QueryBuilder $builder * @param bool $distinctNeeded */ public function processWhereExpression($expression, $value, QueryBuilder $builder, &$distinctNeeded) { list($chain, $operator, $sourceEntity) = ConditionParserHelper::parseCondition($expression); if ($value instanceof Traversable) { $value = iterator_to_array($value); } elseif ($value instanceof IEntity) { $value = $value->getValue('id'); } if (is_array($value) && count($value) === 0) { $builder->andWhere($operator === ConditionParserHelper::OPERATOR_EQUAL ? '1=0' : '1=1'); return; } $sqlExpresssion = $this->normalizeAndAddJoins($chain, $sourceEntity, $builder, $distinctNeeded, $value, $modifier); $operator = $this->getSqlOperator($value, $operator); $builder->andWhere($sqlExpresssion . $operator . $modifier, $value); }
protected function fetch(QueryBuilder $builder, $hasJoin, array $values, IEntityPreloadContainer $preloadContainer = NULL) { $values = array_values(array_unique(array_filter($values, function ($value) { return $value !== NULL; }))); if (count($values) === 0) { return new EntityContainer([], $preloadContainer); } $primaryKey = $this->targetRepository->getMapper()->getStorageReflection()->getStoragePrimaryKey()[0]; $builder->andWhere('%column IN %any', $primaryKey, $values); $builder->addSelect(($hasJoin ? 'DISTINCT ' : '') . '%table.*', $builder->getFromAlias()); $result = $this->connection->queryArgs($builder->getQuerySQL(), $builder->getQueryParameters()); $entities = []; while ($data = $result->fetch()) { $entity = $this->targetRepository->hydrateEntity($data->toArray()); $entities[$entity->getValue('id')] = $entity; } return new EntityContainer($entities, $preloadContainer); }