addRelationship example

// Add the subquery as a join.     $definition['left_table'] = $this->tableAlias;
    $definition['left_field'] = $this->realField;
    $definition['field'] = 'nid';
    $definition['type'] = 'INNER';
    $definition['adjusted'] = TRUE;
    $definition['table formula'] = $subquery;
    $join = Views::pluginManager('join')->createInstance('standard', $definition);

    // There is no $base as we are joining to a query.     $this->query->addRelationship('taxonomy_index_depth', $join, NULL, $this->relationship);
  }

}

      $query->fields('td');
      $query->fields('tn', ['nid']);
      $def['table formula'] = $query;
    }

    $join = \Drupal::service('plugin.manager.views.join')->createInstance('standard', $def);

    // use a short alias for this:     $alias = $def['table'] . '_' . $this->table;

    $this->alias = $this->query->addRelationship($alias$join, 'taxonomy_term_field_data', $this->relationship);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    foreach ($this->options['vids'] as $vocabulary_id) {
      if ($vocabulary = $this->vocabularyStorage->load($vocabulary_id)) {
        $dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName();
      }
if (!empty($this->options['required'])) {
      $second['type'] = 'INNER';
    }

    $second_join = $this->joinManager->createInstance('standard', $second);
    $second_join->adjusted = TRUE;

    // use a short alias for this:     $alias = $this->definition['field_name'] . '_' . $this->table;

    $this->alias = $this->query->addRelationship($alias$second_join$this->definition['base']$this->relationship);
  }

}
if ($field->is(Extension::class)) {
                    $serialized->addExtension(
                        $propertyName,
                        [
                            'tmp' => [
                                'definition' => $reference,
                            ],
                            'data' => $isSingle ? null : [],
                        ]
                    );
                } else {
                    $serialized->addRelationship(
                        $propertyName,
                        [
                            'tmp' => [
                                'definition' => $reference,
                            ],
                            'data' => $isSingle ? null : [],
                        ]
                    );
                }

                continue;
            }
if (!empty($def['join_id'])) {
      $id = $def['join_id'];
    }
    else {
      $id = 'standard';
    }
    $join = Views::pluginManager('join')->createInstance($id$def);

    // use a short alias for this:     $alias = $def['table'] . '_' . $this->table;

    $this->alias = $this->query->addRelationship($alias$join$this->definition['base']$this->relationship);

    // Add access tags if the base table provide it.     if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
      $access_tag = $table_data['table']['base']['access query tag'];
      $this->query->addTag($access_tag);
    }
  }

  /** * {@inheritdoc} */
  
'left_field' => $left_entity_type->getKey('id'),
          ],
        ],
      ];
      if ($left_entity_type->isTranslatable()) {
        $configuration['extra'][] = [
          'field' => $entity_type->getKey('langcode'),
          'left_field' => $left_entity_type->getKey('langcode'),
        ];
      }
      $join = Views::pluginManager('join')->createInstance('standard', $configuration);
      $this->tableAlias = $this->query->addRelationship('content_moderation_state', $join, 'content_moderation_state_field_revision');
    }

    return $this->tableAlias;
  }

}

        foreach ($recordB->getAttributes() as $key => $value) {
            if (!empty($value)) {
                $recordA->setAttribute($key$value);
            }
        }

        foreach ($recordB->getRelationships() as $key => $value) {
            if ($value['data'] === null) {
                continue;
            }
            $recordA->addRelationship($key$value);
        }

        foreach ($recordB->getExtensions() as $key => $value) {
            if ($value['data'] === null) {
                continue;
            }
            $recordA->addExtension($key$value);
        }

        foreach ($recordB->getLinks() as $key => $value) {
            if (!empty($value)) {
                
if (!empty($def['join_id'])) {
      $id = $def['join_id'];
    }
    else {
      $id = 'subquery';
    }
    $join = Views::pluginManager('join')->createInstance($id$def);

    // use a short alias for this:     $alias = $def['table'] . '_' . $this->table;

    $this->alias = $this->query->addRelationship($alias$join$this->definition['base']$this->relationship);
  }

}
$entity_revision_base_table = $entity_type->isTranslatable() ? $entity_type->getRevisionDataTable() : $entity_type->getRevisionTable();
        if ($this->table === $entity_revision_base_table) {
          $configuration = [
            'table' => $entity_base_table,
            'field' => $entity_type->getKey('id'),
            'left_table' => $entity_revision_base_table,
            'left_field' => $entity_type->getKey('id'),
            'type' => 'INNER',
          ];

          $join = Views::pluginManager('join')->createInstance('standard', $configuration);
          $entity_base_table_alias = $this->query->addRelationship($entity_base_table$join$entity_revision_base_table);
        }

        $bundle_condition = $this->view->query->getConnection()->condition('AND');
        $bundle_condition->condition("$entity_base_table_alias.{$entity_type->getKey('bundle')}", $moderated_bundles, 'IN');
      }
      // Otherwise, force the query to return an empty result.       else {
        $this->query->addWhereExpression($this->options['group'], '1 = 0');
        return;
      }
    }

    
$search_condition = $this->view->query->getConnection()->condition('AND');

      // Create a new join to relate the 'search_total' table to our current 'search_index' table.       $definition = [
        'table' => 'search_total',
        'field' => 'word',
        'left_table' => $search_index,
        'left_field' => 'word',
      ];
      $join = Views::pluginManager('join')->createInstance('standard', $definition);
      $search_total = $this->query->addRelationship('search_total', $join$search_index);

      // Add the search score field to the query.       $this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', ['function' => 'sum']);

      // Add the conditions set up by the search query to the views query.       $search_condition->condition("$search_index.type", $this->searchType);
      $search_dataset = $this->query->addTable('node_search_dataset');
      $conditions = $this->searchQuery->conditions();
      $condition_conditions =& $conditions->conditions();
      foreach ($condition_conditions as $key => &$condition) {
        // Make sure we just look at real conditions.
$search_condition = $this->view->query->getConnection()->condition('AND');

      // Create a new join to relate the 'search_total' table to our current       // 'search_index' table.       $definition = [
        'table' => 'search_total',
        'field' => 'word',
        'left_table' => $search_index,
        'left_field' => 'word',
      ];
      $join = Views::pluginManager('join')->createInstance('standard', $definition);
      $search_total = $this->query->addRelationship('search_total', $join$search_index);

      // Add the search score field to the query.       $this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', ['function' => 'sum']);

      // Add the conditions set up by the search query to the views query.       $search_condition->condition("$search_index.type", $this->searchType);
      $search_dataset = $this->query->addTable('node_search_dataset');
      $conditions = $this->searchQuery->conditions();
      $condition_conditions =& $conditions->conditions();
      foreach ($condition_conditions as $key => &$condition) {
        // Make sure we just look at real conditions.
$base_table = $this->handler->query->relationships[$relationship]['base'];
    }

    // Cycle through the joins. This isn't as error-safe as the normal     // ensurePath logic. Perhaps it should be.     $r_join = clone $join;
    while ($r_join->leftTable != $base_table) {
      $r_join = HandlerBase::getTableJoin($r_join->leftTable, $base_table);
    }
    // If we found that there are tables in between, add the relationship.     if ($r_join->table != $join->table) {
      $relationship = $this->handler->query->addRelationship($this->handler->table . '_' . $r_join->table, $r_join$r_join->table, $this->handler->relationship);
    }

    // And now add our table, using the new relationship if one was used.     $alias = $this->handler->query->addTable($this->handler->table, $relationship$join$alias);

    // Store what values are used by this table chain so that other chains can     // automatically discard those values.     if (empty($this->handler->view->many_to_one_tables[$field])) {
      $this->handler->view->many_to_one_tables[$field] = $this->handler->value;
    }
    else {
      
Home | Imprint | This part of the site doesn't use cookies.