Exemple #1
0
 /**
  * Find the nodes related to the relationship
  *
  * @param Property $property
  * @param array $info
  *
  * @return object
  */
 protected function getRelationshipNode(Property $property, array $info)
 {
     $nodeClass = $this->map->getClass($property->getOption('node'));
     foreach ($this->entities as $entity) {
         if (!$entity instanceof $nodeClass) {
             continue;
         }
         $nodeInfo = $this->entities->getInfo($entity);
         if ($nodeInfo['realId'] === $info[$property->getType()]) {
             return $entity;
         }
     }
     $query = new Query(sprintf('MATCH (n:%s) WHERE id(n) = {where}.id RETURN n;', $nodeClass));
     $query->addVariable('n', $nodeClass);
     $query->addParameters('where', ['id' => $info[$property->getType()]]);
     return $this->uow->execute($query)->current();
 }
Exemple #2
0
 /**
  * Clean query parameters by converting via the types defined by the properties
  *
  * @param Query $query
  *
  * @return array
  */
 protected function cleanParameters(Query $query)
 {
     $params = $query->getParameters();
     $references = $query->getReferences();
     $variables = $query->getVariables();
     foreach ($params as $key => &$values) {
         if (!isset($references[$key])) {
             continue;
         }
         foreach ($values as $k => &$value) {
             if (!isset($references[$key][$k])) {
                 continue;
             }
             list($var, $prop) = explode('.', $references[$key][$k]);
             $class = $this->identityMap->getClass($variables[$var]);
             $metadata = $this->metadataRegistry->getMetadata($class);
             if (!$metadata->hasProperty($prop)) {
                 continue;
             }
             $prop = $metadata->getProperty($prop);
             if ($prop->isNullable() && $value === null) {
                 unset($values[$k]);
                 continue;
             }
             $value = Types::getType($prop->getType())->convertToDatabaseValue($value, $prop);
         }
     }
     return $params;
 }
 /**
  * Extract variables and parameters from the expression to inject them into the query
  *
  * @param Query $query
  * @param ExpressionInterface $expression
  *
  * @return void
  */
 protected function extractData(Query $query, ExpressionInterface $expression)
 {
     if ($expression instanceof ParametrableExpressionInterface && $expression->hasParameters()) {
         $query->addParameters($expression->getParametersKey(), $expression->getParameters(), $expression->getReferences());
     }
     if ($expression instanceof VariableAwareInterface && $expression->hasVariable() && $expression->hasAlias()) {
         $query->addVariable($expression->getVariable(), $expression->getAlias());
     }
 }