private function createAttributesQuery(User $user)
    {
        $query = $this->getEntityManager()
            ->createQuery('
                SELECT ua
                FROM UserBundle:UserAttribute ua
                LEFT JOIN ua.groups ug
                INDEX BY ua.id
                WHERE ug.id IN (:groupIds)
            ')
        ->setParameters([
            ':groupIds' => $user->getGroupIds(),
        ]);

        return $query;
    }