1

I'm trying to builder this data query

select * 
from user 
where user.id not in (
    select user.id 
    from user 
    inner join repo_user 
    on user.id = repo_user.userId 
    where repo_user.repoId = $id
)

And I reference the answer 'where not in' query with doctrine query builder

My trying

class UserRepository extends EntityRepository
{
    public function excludeUser($id)
    {
        $q1 = $this->createQueryBuilder('u')
                ->select('u.id')
                ->innerJoin('SvnAdminBundle:RepoUser', 'ru', 'WITH', "ru.userid = u.id")
                ->where("ru.repoid = $id")
                ->getQuery()
                ->getResult();

        $qb = $this->createQueryBuilder('r');
        $result = $qb->where($qb->expr()->notIn('r.id', $q1))
                ->getQuery()
                ->getResult();

        return $result;
    }
}

And I get the error message

Notice: Array to string conversion

Community
  • 1
  • 1
nidiac
  • 13
  • 3

1 Answers1

1

You should give a string as second parameter of notIn, right now you are passing your result which is an array, dont fetch the result with the first query. use

$q1 = $this->createQueryBuilder('u')
                ->select('u.id')
                ->innerJoin('SvnAdminBundle:RepoUser', 'ru', 'WITH', "ru.userid = u.id")
                ->where("ru.repoid = $id")
                ->getDQL();
Nawfal Serrar
  • 2,213
  • 1
  • 14
  • 22