We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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
            )
        );


85.5k


6.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 :)