Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

ModelsManager: The index does not exist in the cursor

Hello Phalconeers

I'm having this error while trying to call the function executeQuery on the modelsManager i'm getting this error when the query does not match any records but when it does it works just fine, and there is not exception to catch?

Phalcon Version: 2.0.9 Platform: Ubuntu 14.04 PHP Version: 5.5.9

Error: The index does not exist in the cursor

Code :

            $phql = "SELECT
                *
             FROM
                PosAccessTokens,
                CustomerUsers
            WHERE
               PosAccessTokens.accessToken = :token:
            AND
                PosAccessTokens.userID = CustomerUsers.userID";

        $token = $this->modelsManager->executeQuery(
            $phql,
            array(
                'token' => $token
            )
        );


64.4k


2.4k
Accepted
answer

Ended up using the builder functionality and it works perfectly:

    $token = $this->modelsManager->createBuilder()
        ->from('PosAccessTokens')
        ->join('CustomerUsers')
        ->where('PosAccessTokens.accessToken = :token:', array('token' => $token))
        ->andWhere('PosAccessTokens.userID = CustomerUsers.userID')
        ->getQuery()
        ->execute();

You don't use JOIN in your first example, so the two queries are not exactly the same...

SELECT * FROM PosAccessTokens, CustomerUsers WHERE ...

I also tried with join with the createQuery function with the same result... And even an simple SELECT * FROM PosAccessTokens WHERE token = :token: - Did not work too... So pretty weird

You should upgrade Phalcon Version: 2.0.9 to the latest (2.0.13).

I'll try upgrade tonight, i'll keep you postet :)