Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Incorrect return type hint of Phalcon\Mvc\Model\Manager::executeQuery() #15024

Closed
sergeyklay opened this issue May 6, 2020 · 1 comment · Fixed by #15026
Closed

[BUG]: Incorrect return type hint of Phalcon\Mvc\Model\Manager::executeQuery() #15024

sergeyklay opened this issue May 6, 2020 · 1 comment · Fixed by #15026
Assignees
Labels
bug A bug report status: low Low

Comments

@sergeyklay
Copy link
Contributor

sergeyklay commented May 6, 2020

The current implementation of Phalcon\Mvc\Model\Manager::executeQuery implies that method must return a Phalcon\Mvc\Model\QueryInterface instance:

public function executeQuery(string! phql, var placeholders = null, var types = null) -> <QueryInterface>
{
var query;
let query = this->createQuery(phql);
if typeof placeholders == "array" {
query->setBindParams(placeholders);
}
if typeof types == "array" {
query->setBindTypes(types);
}
/**
* Execute the query
*/
return query->execute();
}

however, this method returns at least an instance of the following interfaces:

  • Phalcon\Mvc\Model\ResultsetInterface
  • Phalcon\Mvc\Model\Query\StatusInterface
use Phalcon\Db\Adapter\PdoFactory;
use Phalcon\Di;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Model;

Di::setDefault($container = new FactoryDefault());

$container->setShared(
    'db',
    (new PdoFactory())->newInstance(
        'sqlite',
        ['dbname' => '/tmp/test.sqlite']
    )
);

class Objects extends Model
{
    public $obj_id;
    public $obj_name;
    public $obj_type;
}

class ObjectDetails extends Model
{
    public $obj_id;
    public $details;
}

$app = new Application($container);

$sql = <<<EOF
SELECT
    o.obj_name,
    o.obj_type,
    od.*
FROM
    Objects AS o
LEFT JOIN ObjectDetails AS od ON
    od.obj_id = o.obj_id
WHERE
    o.obj_id = :obj_id:
EOF;

echo $sql, PHP_EOL;

$result = $app->modelsManager->executeQuery($sql, ['obj_id' => 1]);
var_dump(get_class($result)); // FATAL ERROR

This leads to a fatal error:

PHP Fatal error:
Return value of Phalcon\Mvc\Model\Manager::executeQuery()
must implement interface Phalcon\Mvc\Model\QueryInterface, instance of Phalcon\Mvc\Model\Resultset\Complex returned

For the database schema see: #14657

@sergeyklay sergeyklay added bug A bug report status: unverified Unverified 4.0.6 status: low Low and removed status: unverified Unverified labels May 6, 2020
@sergeyklay sergeyklay self-assigned this May 6, 2020
@sergeyklay sergeyklay linked a pull request May 6, 2020 that will close this issue
5 tasks
@sergeyklay
Copy link
Contributor Author

Fixed in 4.0.x branch

@niden niden moved this to Released in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant