Gets the relationship from a Join expression.

@deprecated
771134
public static function getJoinRelationship(Join $join): string
    {
        @trigger_error(sprintf('The use of "%s::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getJoin()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);

        return $join->getJoin();
    }
404611
public function JoinAssociationPathExpression()
    {
        $identVariable = $this->IdentificationVariable();

        if ( ! isset($this->queryComponents[$identVariable])) {
            $this->semanticalError(
                'Identification Variable ' . $identVariable .' used in join path expression but was not defined before.'
            );
        }

        $this->match(Lexer::T_DOT);
        $this->match(Lexer::T_IDENTIFIER);

        $field = $this->lexer->token['value'];

        // Validate association field
        $qComp = $this->queryComponents[$identVariable];
        $class = $qComp['metadata'];

        if ( ! $class->hasAssociation($field)) {
            $this->semanticalError('Class ' . $class->name . ' has no association named ' . $field);
        }

        return new AST\JoinAssociationPathExpression($identVariable, $field);
    }
1038763
public function getJoinString()
    {
        $statement = "";
        
        foreach ($this->join as $i => $join) {
            $statement .= " " . $join['type'] . " " . $join['table'];
            
            if ($join['alias']) {
                $statement .= " AS " . $join['alias'];
            }
            
            // Add ON criteria if specified.
            if ($join['criteria']) {
                $statement .= " ON ";
                
                foreach ($join['criteria'] as $x => $criterion) {
                    // Logically join each criterion with AND.
                    if ($x != 0) {
                        $statement .= " " . self::LOGICAL_AND . " ";
                    }
                    
                    // If the criterion does not include an equals sign, assume a
                    // column name and join against the same column from the previous
                    // table.
                    if (strpos($criterion, '=') === false) {
                        $statement .= $this->getJoinCriteriaUsingPreviousTable($i, $join['table'], $criterion);
                    } else {
                        $statement .= $criterion;
                    }
                }
            }
        }
        
        $statement = trim($statement);
        
        return $statement;
    }
49946
protected function _getRelationshipValue($relationship)
    {
        if (!isset($this->_relatedObjects[$relationship])) {
            $rel = static::$_classRelationships[get_called_class()][$relationship];

            if ($rel['type'] == 'one-one') {
                if ($value = $this->_getFieldValue($rel['local'])) {
                    $this->_relatedObjects[$relationship] = $rel['class']::getByField($rel['foreign'], $value);
                
                    // hook relationship for invalidation
                    static::$_classFields[get_called_class()][$rel['local']]['relationships'][$relationship] = true;
                } else {
                    $this->_relatedObjects[$relationship] = null;
                }
            } elseif ($rel['type'] == 'one-many') {
                if (!empty($rel['indexField']) && !$rel['class']::fieldExists($rel['indexField'])) {
                    $rel['indexField'] = false;
                }
                
                $this->_relatedObjects[$relationship] = $rel['class']::getAllByWhere(
                    array_merge($rel['conditions'], [
                        $rel['foreign'] => $this->_getFieldValue($rel['local']),
                    ]),
                
                    [
                        'indexField' => $rel['indexField'],
                        'order' => $rel['order'],
                        'conditions' => $rel['conditions'],
                    ]
                );
                
                
                // hook relationship for invalidation
                static::$_classFields[get_called_class()][$rel['local']]['relationships'][$relationship] = true;
            } elseif ($rel['type'] == 'context-children') {
                if (!empty($rel['indexField']) && !$rel['class']::fieldExists($rel['indexField'])) {
                    $rel['indexField'] = false;
                }

                $conditions = array_merge($rel['conditions'], [
                    'ContextClass' => $rel['contextClass'],
                    'ContextID' => $this->_getFieldValue($rel['local']),
                ]);
            
                $this->_relatedObjects[$relationship] = $rel['class']::getAllByWhere(
                    $conditions,
            
                    [
                        'indexField' => $rel['indexField'],
                        'order' => $rel['order'],
                    ]
                );
                
                // hook relationship for invalidation
                static::$_classFields[get_called_class()][$rel['local']]['relationships'][$relationship] = true;
            } elseif ($rel['type'] == 'context-parent') {
                $className = $this->_getFieldValue($rel['classField']);
                $this->_relatedObjects[$relationship] = $className ? $className::getByID($this->_getFieldValue($rel['local'])) : null;
                
                // hook both relationships for invalidation
                static::$_classFields[get_called_class()][$rel['classField']]['relationships'][$relationship] = true;
                static::$_classFields[get_called_class()][$rel['local']]['relationships'][$relationship] = true;
            } elseif ($rel['type'] == 'many-many') {
                if (!empty($rel['indexField']) && !$rel['class']::fieldExists($rel['indexField'])) {
                    $rel['indexField'] = false;
                }
                
                // TODO: support indexField, conditions, and order
                
                $this->_relatedObjects[$relationship] = $rel['class']::getAllByQuery(
                    'SELECT Related.* FROM `%s` Link JOIN `%s` Related ON (Related.`%s` = Link.%s) WHERE Link.`%s` = %u AND %s',
                
                    [
                        $rel['linkClass']::$tableName,
                        $rel['class']::$tableName,
                        $rel['foreign'],
                        $rel['linkForeign'],
                        $rel['linkLocal'],
                        $this->_getFieldValue($rel['local']),
                        $rel['conditions'] ? join(' AND ', $rel['conditions']) : '1',
                    ]
                );
                
                // hook relationship for invalidation
                static::$_classFields[get_called_class()][$rel['local']]['relationships'][$relationship] = true;
            } elseif ($rel['type'] == 'history' && static::isVersioned()) {
                $this->_relatedObjects[$relationship] = $rel['class']::getRevisionsByID($this->getPrimaryKeyValue(), $rel);
            }
        }
        
        return $this->_relatedObjects[$relationship];
    }
628371
private function optimizeOneToOneRelationsAsLeftJoins(Select $select, array $memberMappings) : array
    {
        $joinedRelationTableAliasMap = [];

        foreach ($memberMappings as $key => $mappingWithAlias) {
            $relationKey       = '';
            $mapping           = $mappingWithAlias->getMapping();
            $tableAliases      = $mappingWithAlias->getTableAliases();
            $relationsToRemove = 0;

            foreach ($mapping->getRelationsToSubSelect() as $relation) {
                $relationKey .= $relation->getIdString();

                if ($relation instanceof IToOneRelation && $relation instanceof ISeparateTableRelation) {
                    if (isset($joinedRelationTableAliasMap[$relationKey])) {
                        $tableAliases[] = $joinedRelationTableAliasMap[$relationKey];
                    } else {
                        $tableAliases[] = $tableAlias = $relation->joinSelectToRelatedTable(end($tableAliases), Join::LEFT, $select);

                        $joinedRelationTableAliasMap[$relation->getIdString()] = $tableAlias;
                    }
                } elseif ($relation instanceof IToManyRelation) {
                    break;
                }

                $relationsToRemove++;
            }

            $memberMappings[$key] = new MemberMappingWithTableAliases(
                $mapping->withoutRelationsToSubSelect($relationsToRemove),
                $tableAliases
            );
        }

        return $memberMappings;
    }
26157
@Override
    public List<org.fcrepo.server.types.gen.RelationshipTuple> getRelationships(String pid,
                                                                                String relationship) {
        LOG.debug("start: getRelationships");
        assertInitialized();
        try {
            MessageContext ctx = context.getMessageContext();
            org.fcrepo.server.storage.types.RelationshipTuple[] intRelationshipTuples =
                    null;
            intRelationshipTuples =
                    m_management.getRelationships(ReadOnlyContext
                            .getSoapContext(ctx), pid, relationship);
            return getGenRelsTuples(intRelationshipTuples);
        } catch (Throwable th) {
            LOG.error("Error getting relationships", th);
            throw CXFUtility.getFault(th);
        } finally {
            LOG.debug("end: getRelationships");
        }
    }
451444
public function getRelationships()
    {
        if (empty(static::$relationHooks)) {
            $hooks = [];

            $rels = $this->getRelationshipsFromMethods(true);

            $this->getRelationshipsUnknownPolyMorph($rels, $hooks);

            $this->getRelationshipsKnownPolyMorph($rels, $hooks);

            $this->getRelationshipsHasOne($rels, $hooks);

            $this->getRelationshipsHasMany($rels, $hooks);

            static::$relationHooks = $hooks;
        }

        return static::$relationHooks;
    }
1071828
function getPathFromMemberExpression(expr, acc = []) {
  if (expr.type === "Identifier") {
    return acc.concat(expr.name);
  } else if (expr.type === "MemberExpression") {
    return acc.concat(getPathFromMemberExpression(expr.object, acc)).concat(expr.property.name);
  } else {
    throw new Error(`Expected MemberExpression or Identifier but get ${expr.type}.`);
  }
}
601484
public Class<?> getRelationshipType(Class<?> clazz, String fieldName) {
		return relationshipTypeMap.get(clazz).get(fieldName);
	}
1140615
protected List<String> getEdges(String join) {
        List<String> results = new ArrayList<>();
        for (Many2ManyAssociation a : many2ManyAssociations) {
            if (a.getJoin().equalsIgnoreCase(join)) {
                results.add(getMetaModel(a.getSourceClass()).getTableName());
                results.add(getMetaModel(a.getTargetClass()).getTableName());
            }
        }
        return results;
    }
48369
protected CSRelatedNodeWrapper findExistingRelatedNode(final Relationship relationship,
            final List<CSRelatedNodeWrapper> topicRelatedNodes) {
        if (topicRelatedNodes != null) {
            // Loop over the current nodes and see if any match
            for (final CSRelatedNodeWrapper relatedNode : topicRelatedNodes) {
                if (relationship instanceof TargetRelationship) {
                    if (doesRelationshipMatch((TargetRelationship) relationship, relatedNode)) {
                        return relatedNode;
                    }
                } else {
                    if (doesRelationshipMatch((TopicRelationship) relationship, relatedNode)) {
                        return relatedNode;
                    }
                }
            }
        }

        return null;
    }
215169
private function getRelationValue($property) {
        $propertyName = $property;
        /** @var PersistableObject|PersistableObject[]|scalar|null $value */
        $value = &$this->$propertyName;                                 // existing property value

        if (is_object($value)) return $value;                           // relation is fetched and is an object or an array
        if (is_array ($value)) return $value;                           // (Collections are not yet implemented)

        $dao          =  $this->dao();
        $mapping      =  $dao->getMapping();
        $relation     = &$mapping['relations'][$propertyName];
        $isCollection = strEndsWith($relation['assoc'], 'many');
        /** @var PersistableObject[]|null $emptyResult */
        $emptyResult  = $isCollection ? [] : null;

        if ($value === null) {
            if (!$this->isPersistent())
                return $emptyResult;
        }
        else if ($value === false) {                                    // relation is fetched and marked as empty
            return $emptyResult;
        }

        // The relation is not yet fetched, the property is NULL or holds a physical foreign-key value.
        $type           = $relation['type'];                            // related class name
        /** @var DAO $relatedDao */
        $relatedDao     = $type::dao();
        $relatedMapping = $relatedDao->getMapping();
        $relatedTable   = $relatedMapping['table'];

        if ($value === null) {
            if (isset($relation['column'])) {                           // a local column with a foreign-key value of NULL
                $value = false;
                return $emptyResult;                                    // the relation is marked as empty
            }

            // a local key is used
            if (!isset($relation['key']))
                $relation['key'] = $mapping['identity']['name'];        // default local key is identity
            $keyName = $relation['key'];                                // the used local key property
            if ($this->$keyName === null) {
                $value = false;                                         // the relation is marked as empty
                return $emptyResult;
            }
            $keyColumn = $mapping['properties'][$keyName]['column'];    // the used local key column
            $refColumn = $relation['ref-column'];                       // the referencing column

            if (!isset($relation['join-table'])) {
                // the referencing column is part of the related table
                $refColumnType = $relatedMapping['columns'][$refColumn]['type'];
                $refValue      = $relatedDao->escapeLiteral($this->getPhysicalValue($keyColumn, $refColumnType));
                $sql = 'select r.*
                            from '.$relatedTable.' r
                            where r.'.$refColumn.' = '.$refValue;
            }
            else {
                // the referenced column is part of a join table
                $joinTable = $relation['join-table'];
                $keyValue  = $dao->escapeLiteral($this->getPhysicalValue($keyColumn));  // the physical local key value

                if (!isset($relation['foreign-key']))
                    $relation['foreign-key'] = $relatedMapping['identity']['name'];     // default foreign-key is identity
                $fkName      = $relation['foreign-key'];                                // the used foreign-key property
                $fkColumn    = $relatedMapping['properties'][$fkName]['column'];        // the used foreign-key column
                $fkRefColumn = $relation['fk-ref-column'];                              // join column referencing the foreign-key
                $sql = 'select r.*
                            from '.$relatedTable.' r
                            join '.$joinTable.'    j on r.'.$fkColumn.' = j.'.$fkRefColumn.'
                            where j.'.$refColumn.' = '.$keyValue;
            }
            if ($isCollection) {                                                        // default result sorting
                $relatedIdColumn = $relatedMapping['identity']['column'];               // the related identity column
                $sql .= ' order by r.'.$relatedIdColumn;                                // sort by identity
            }
        }
        else {
            // $value holds a non-NULL column-type foreign-key value pointing to a single related record
            if (isset($relation['join-table'])) {
                if (!isset($relation['foreign-key']))
                    $relation['foreign-key'] = $relatedMapping['identity']['name'];     // default foreign-key is identity
                $fkName   = $relation['foreign-key'];                                   // the used foreign-key property
                $fkColumn = $relatedMapping['properties'][$fkName]['column'];           // the used foreign-key column
            }
            else if (isset($relation['column'])) {                      // a local column referencing the foreign key
                if (!isset($relation['ref-column']))                    // default foreign-key is identity
                    $relation['ref-column'] = $relatedMapping['identity']['column'];
                $fkColumn = $relation['ref-column'];                    // the used foreign-key column
            }
            else {
                $fkColumn = $relatedMapping['identity']['column'];      // the used foreign-key column is identity
            }
            $fkValue = $relatedDao->escapeLiteral($value);
            $sql = 'select r.*
                        from '.$relatedTable.' r
                        where r.'.$fkColumn.' = '.$fkValue;
        }

        if (!$isCollection) $value = $relatedDao->find($sql);           // => PersistableObject
        else                $value = $relatedDao->findAll($sql);        // => PersistableObject[]

        return $value;
    }
1132684
private String getJoinColumnName(Field relation)
    {
        String columnName = null;
        JoinColumn ann = relation.getAnnotation(JoinColumn.class);
        if (ann != null)
        {
            columnName = ann.name();

        }
        return StringUtils.isBlank(columnName) ? relation.getName() : columnName;
    }
744105
function getRelated() {
  var relatedValues = getValue(this, 'see');
  if (relatedValues && relatedValues.trim().length > 0) {
    var relatedItems = relatedValues.split(',').map((relatedItem) => relatedItem.trim());
    return relatedItems.map((relatedItem) => '[' + relatedItem + '](#' + relatedItem + ')');
  } else {
    return [];
  }
}
90674
function join($relation, $expr = null, $mode = Join::INNER)
    {
        if (null !== $expr) {
            $expr = new On(new AndX(array($expr)));
        }

        $join = new Join($relation, $expr);
        $join->mode = $mode;

        $this->nodes->source->right[] = $join;
        return $this;
    }
620878
private ImmutableMultimap<RelationDefinition, ExtensionalDataNode> extractDataNodeMap(IntermediateQuery query,
                                                                                          InnerJoinNode joinNode) {
        return query.getChildren(joinNode).stream()
                .filter(c -> c instanceof ExtensionalDataNode)
                .map(c -> (ExtensionalDataNode) c)
                .map(c -> Maps.immutableEntry(c.getProjectionAtom().getPredicate().getRelationDefinition(), c))
                .collect(ImmutableCollectors.toMultimap());
    }
516198
public function getRelation($subRelation = '', $closure = null)
    {
        if ($closure) {
            $closure($this->query);
        }

        $this->baseQuery();

        $list   = $this->query->relation($subRelation)->select();
        $parent = clone $this->parent;

        foreach ($list as &$model) {
            $model->setParent($parent);
        }

        return $list;
    }