src/Model/Table/UsersTable.php
public function findUsersWithNoGroup()
    {
        $query = $this->find();

        return $query->leftJoin(
                [$this->UsersGroups->alias() => $this->UsersGroups->table()],
                [$this->aliasField('id') . ' = ' . $this->UsersGroups->aliasField('user_id')]
            )
            ->select([
                'Users.id',
                'group_count' => $query->func()->count('UsersGroups.group_id')
            ])
            ->group('Users.id')
            ->having('group_count = 0');
    }
public function findUsersWithNoGroup()
    {
        $query = $this->find();

        return $query->leftJoin(
                [$this->UsersGroups->alias() => $this->UsersGroups->table()],
                [$this->aliasField('id') . ' = ' . $this->UsersGroups->aliasField('user_id')]
            )
            ->select([
                'Users.id',
                'group_count' => $query->func()->count('UsersGroups.group_id')
            ])
            ->group('Users.id')
            ->having('group_count = 0');
    }
public function findUsersWithNoGroup ( ) { $ query = $ this -> find ( ) ; return $ query -> leftJoin ( [ $ this -> UsersGroups -> alias ( ) => $ this -> UsersGroups -> table ( ) ] , [ $ this -> aliasField ( 'id' ) . ' = ' . $ this -> UsersGroups -> aliasField ( 'user_id' ) ] ) -> select ( [ 'Users.id' , 'group_count' => $ query -> func ( ) -> count ( 'UsersGroups.group_id' ) ] ) -> group ( 'Users.id' ) -> having ( 'group_count = 0' ) ; }
Find all users that do not belong to a group.

@return Query
Find all users that do not belong to a group .