Helper method used to get the property names of associations for a table.

@param array $associated Whitelist of associations to look for
@return array List of property names
322260
protected function getAssociationProperties($associated)
    {
        $associations = $this->_table->associations();
        $result = [];

        foreach ($associated as $name) {
            $result[] = $associations->get($name)->getProperty();
        }

        return $result;
    }
248475
private function searchAssociationField($associationsByTargetClass, $parentTable, $value)
    {
        foreach ($associationsByTargetClass as $table => $association) {
            if ($table == $parentTable && $association['inversedBy'] == $value) {
                return $association['fieldName'];
            }
        }
    }
762950
protected function _scaffoldFields(array $associations = [])
    {
        $action = $this->_action();
        $scaffoldFields = (array)$action->getConfig('scaffold.fields');
        if (!empty($scaffoldFields)) {
            $scaffoldFields = Hash::normalize($scaffoldFields);
        }

        if (empty($scaffoldFields) || $action->getConfig('scaffold.autoFields')) {
            $cols = $this->_table()->getSchema()->columns();
            $cols = Hash::normalize($cols);

            $scope = $action->getConfig('scope');
            if ($scope === 'entity' && !empty($associations['manyToMany'])) {
                foreach ($associations['manyToMany'] as $alias => $options) {
                    $cols[sprintf('%s._ids', $options['entities'])] = [
                        'multiple' => true
                    ];
                }
            }

            $scaffoldFields = array_merge($cols, $scaffoldFields);
        }

        // Check for blacklisted fields
        $blacklist = $action->getConfig('scaffold.fields_blacklist');
        if (!empty($blacklist)) {
            $scaffoldFields = array_diff_key($scaffoldFields, array_combine($blacklist, $blacklist));
        }

        // Make sure all array values are an array
        foreach ($scaffoldFields as $field => $options) {
            if (!is_array($options)) {
                $scaffoldFields[$field] = (array)$options;
            }

            $scaffoldFields[$field] += ['formatter' => null];
        }

        $fieldSettings = $action->getConfig('scaffold.field_settings');
        if (empty($fieldSettings)) {
            $fieldSettings = [];
        }
        $fieldSettings = array_intersect_key($fieldSettings, $scaffoldFields);
        $scaffoldFields = Hash::merge($scaffoldFields, $fieldSettings);

        return $scaffoldFields;
    }
927462
public function associate(Association $association, Entry $entry, $input)
    {
        if ($association instanceof ManyToOneAssociation) {
            return $this->associateManyToOne($association, $entry, $input);
        }
        if ($association instanceof OneToOneAssociation) {
            return $this->associateOneToOne($association, $entry, $input);
        }
        if ($association instanceof OneToManyAssociation) {
            return $this->associateOneToMany($association, $entry, $input);
        }
        if ($association instanceof ManyToManyAssociation) {
            return $this->associateManyToMany($association, $entry, $input);
        }
    }
461338
public function getEntryAssociation(Association $association)
    {
        $id = $association->getId();

        /**
         * @var EntryAssociation $entryAssociation
         */
        foreach ($this->associations as $entryAssociation) {
            if ($entryAssociation->getAssociation()->getId() === $id) {
                return $entryAssociation;
            }
        }

        return null;
    }
1321975
public function getSuperGroup($associatedProducts)
    {
        $superGroup = [];
        foreach ($associatedProducts as $associatedProduct) {
            $superGroup[$associatedProduct->getId()] = 1;
        }

        return $superGroup;
    }
103772
public function getAssociatedByType($types = [])
    {
        $return = [];

        $table = $this->_table();
        foreach ($table->associations()->keys() as $association) {
            $associationClass = $table->associations()->get($association);
            if (!in_array($associationClass->type(), $types)) {
                continue;
            }

            $return[$associationClass->getName()] = $associationClass;
        }

        return $return;
    }
625171
function _allAssocs()
    {
        $all_associations = array();

        $association_filenames =
            Auth_OpenID_FileStore::_listdir($this->association_dir);

        foreach ($association_filenames as $association_filename) {
            $association_file = fopen($association_filename, 'rb');

            if ($association_file !== false) {
                $assoc_s = fread($association_file,
                                 filesize($association_filename));
                fclose($association_file);

                // Remove expired or corrupted associations
                $association =
                  Auth_OpenID_Association::deserialize(
                         'Auth_OpenID_Association', $assoc_s);

                if ($association === null) {
                    Auth_OpenID_FileStore::_removeIfPresent(
                                                 $association_filename);
                } else {
                    if ($association->getExpiresIn() == 0) {
                        $all_associations[] = array($association_filename,
                                                    $association);
                    }
                }
            }
        }

        return $all_associations;
    }
522059
protected function getJoinSQLForAssociation(AssociationMetadata $association)
    {
        if (! $association->isOwningSide()) {
            return 'LEFT JOIN';
        }

        // if one of the join columns is nullable, return left join
        foreach ($association->getJoinColumns() as $joinColumn) {
            if (! $joinColumn->isNullable()) {
                continue;
            }

            return 'LEFT JOIN';
        }

        return 'INNER JOIN';
    }
372384
public function getAssociationReferenceNames()
    {
        $referenceNames = array();
        foreach ($this->associationMappings as $assoc) {
            $referenceNames[] = $assoc->getReferenceField($this->getManagerIdentifier()) ?: $assoc->getField();
        }

        return $referenceNames;
    }
510051
protected function _associations(array $whitelist = [])
    {
        $table = $this->_table();

        $associationConfiguration = [];

        $associations = $table->associations();

        $keys = $associations->keys();
        if (!empty($whitelist)) {
            $keys = array_intersect($keys, array_map('strtolower', $whitelist));
        }
        foreach ($keys as $associationName) {
            $association = $associations->get($associationName);
            $type = $association->type();

            if (!isset($associationConfiguration[$type])) {
                $associationConfiguration[$type] = [];
            }

            $assocKey = $association->getName();
            $associationConfiguration[$type][$assocKey]['model'] = $assocKey;
            $associationConfiguration[$type][$assocKey]['type'] = $type;
            $associationConfiguration[$type][$assocKey]['primaryKey'] = $association->getTarget()->getPrimaryKey();
            $associationConfiguration[$type][$assocKey]['displayField'] = $association->getTarget()->getDisplayField();
            $associationConfiguration[$type][$assocKey]['foreignKey'] = $association->getForeignKey();
            $associationConfiguration[$type][$assocKey]['propertyName'] = $association->getProperty();
            $associationConfiguration[$type][$assocKey]['plugin'] = pluginSplit($association->getClassName())[0];
            $associationConfiguration[$type][$assocKey]['controller'] = $assocKey;
            $associationConfiguration[$type][$assocKey]['entity'] = Inflector::singularize(Inflector::underscore($assocKey));
            $associationConfiguration[$type][$assocKey]['entities'] = Inflector::underscore($assocKey);

            $associationConfiguration[$type][$assocKey] = array_merge($associationConfiguration[$type][$assocKey], $this->_action()->getConfig('association.' . $assocKey) ?: []);
        }

        return $associationConfiguration;
    }
1282728
protected function getOnConditionSQL(ManyToManyAssociationMetadata $association)
    {
        $targetClass       = $this->em->getClassMetadata($association->getTargetEntity());
        $owningAssociation = ! $association->isOwningSide()
            ? $targetClass->getProperty($association->getMappedBy())
            : $association;

        $joinTable   = $owningAssociation->getJoinTable();
        $joinColumns = $association->isOwningSide()
            ? $joinTable->getInverseJoinColumns()
            : $joinTable->getJoinColumns();

        $conditions = [];

        foreach ($joinColumns as $joinColumn) {
            $quotedColumnName           = $this->platform->quoteIdentifier($joinColumn->getColumnName());
            $quotedReferencedColumnName = $this->platform->quoteIdentifier($joinColumn->getReferencedColumnName());

            $conditions[] = ' t.' . $quotedColumnName . ' = te.' . $quotedReferencedColumnName;
        }

        return $conditions;
    }
1103705
public static function getTableAssignationFields(Table $table): array
    {
        $fields = [];
        $assignationModels = Configure::read('RolesCapabilities.accessCheck.assignationModels');

        foreach ($table->associations() as $association) {
            // skip non-assignation models
            if (!in_array($association->className(), $assignationModels)) {
                continue;
            }

            $fields[] = $association->getForeignKey();
        }

        return $fields;
    }
796668
public function getQuotedIdentifierColumnNames($platform)
    {
        $quotedColumnNames = array();

        foreach ($this->identifier as $idProperty) {
            if (isset($this->fieldMappings[$idProperty])) {
                $quotedColumnNames[] = isset($this->fieldMappings[$idProperty]['quoted'])
                    ? $platform->quoteIdentifier($this->fieldMappings[$idProperty]['columnName'])
                    : $this->fieldMappings[$idProperty]['columnName'];

                continue;
            }

            // Association defined as Id field
            $joinColumns            = $this->associationMappings[$idProperty]['joinColumns'];
            $assocQuotedColumnNames = array_map(
                function ($joinColumn) use ($platform) {
                    return isset($joinColumn['quoted'])
                        ? $platform->quoteIdentifier($joinColumn['name'])
                        : $joinColumn['name'];
                },
                $joinColumns
            );

            $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames);
        }

        return $quotedColumnNames;
    }
972233
public function getRootAssociations($associationsFilter = null)
    {
        $arrayWithChilds = $this->associationsApiService->getRootAssociations($associationsFilter);

        $associations = new Associations();

        foreach ($arrayWithChilds as $xmlQuery) {
            $association = new Association();

            $mapper = new \RGU\Dvoconnector\Mapper\Association($xmlQuery);
            $mapper->mapToAbstractEntity($association);

            $associations->addAssociation($this->completeEntity($association));
        }

        return $this->completeEntity($associations);
    }
1228934
private function resolveAssociations(Entity $config, ClassMetadata $metadata)
    {
        $associations = [];
        foreach ($metadata->getAssociationMappings() as $associationMapping) {
            $fieldName = $associationMapping['fieldName'];
            $fieldClass = array_filter($config->listFields(), function (ListField $field) use ($fieldName) {
                if (!isset($field->options()['field'])) {
                    return;
                }

                return $fieldName === explode('.', $field->options()['field'])[0];
            });

            if (count($fieldClass) > 0) {
                $associations[] = $fieldName;
            }
        }

        return $associations;
    }
901156
public function getAssociationCollectionClass(string $assocName) : string
    {
        if (! isset($this->associationMappings[$assocName])) {
            throw new InvalidArgumentException("Association name expected, '" . $assocName . "' is not an association.");
        }

        if (! array_key_exists('collectionClass', $this->associationMappings[$assocName])) {
            throw new InvalidArgumentException("collectionClass can only be applied to 'embedMany' and 'referenceMany' associations.");
        }

        return $this->associationMappings[$assocName]['collectionClass'];
    }