protected function _getContainedAssociations($repository, $contains)
    {
        $associationCollection = $repository->associations();
        $associations = [];

        foreach ($contains as $contain => $nestedContains) {
            if (is_string($nestedContains)) {
                $contain = $nestedContains;
                $nestedContains = [];
            }

            $association = $associationCollection->get($contain);
            if ($association === null) {
                continue;
            }

            $associationKey = strtolower($association->getName());

            $associations[$associationKey] = [
                'association' => $association,
                'children' => []
            ];

            if (!empty($nestedContains)) {
                $associations[$associationKey]['children'] = $this->_getContainedAssociations($association->getTarget(), $nestedContains);
            }
        }

        return $associations;
    }
protected function _getContainedAssociations($repository, $contains)
    {
        $associationCollection = $repository->associations();
        $associations = [];

        foreach ($contains as $contain => $nestedContains) {
            if (is_string($nestedContains)) {
                $contain = $nestedContains;
                $nestedContains = [];
            }

            $association = $associationCollection->get($contain);
            if ($association === null) {
                continue;
            }

            $associationKey = strtolower($association->getName());

            $associations[$associationKey] = [
                'association' => $association,
                'children' => []
            ];

            if (!empty($nestedContains)) {
                $associations[$associationKey]['children'] = $this->_getContainedAssociations($association->getTarget(), $nestedContains);
            }
        }

        return $associations;
    }
protected function _getContainedAssociations ( $ repository , $ contains ) { $ associationCollection = $ repository -> associations ( ) ; $ associations = [ ] ; foreach ( $ contains as $ contain => $ nestedContains ) { if ( is_string ( $ nestedContains ) ) { $ contain = $ nestedContains ; $ nestedContains = [ ] ; } $ association = $ associationCollection -> get ( $ contain ) ; if ( $ association === null ) { continue ; } $ associationKey = strtolower ( $ association -> getName ( ) ) ; $ associations [ $ associationKey ] = [ 'association' => $ association , 'children' => [ ] ] ; if ( ! empty ( $ nestedContains ) ) { $ associations [ $ associationKey ] [ 'children' ] = $ this -> _getContainedAssociations ( $ association -> getTarget ( ) , $ nestedContains ) ; } } return $ associations ; }
Creates a nested array of all associations used in the query

@param \Cake\Datasource\RepositoryInterface $repository Repository
@param array $contains Array of contained associations
@return array Array with \Cake\ORM\AssociationCollection
Creates a nested array of all associations used in the query