Hi,
I experienced a strange behavior when I tried to update a table with ModelsManager.
$q = "UPDATE [\Main\Models\TopBanners] as top_banners SET top_banners.banner_id = NULL WHERE top_banners.banner_id NOT IN (SELECT banners.id FROM [\Main\Models\Banners] AS banners)";
$result = $this->modelsManager->executeQuery($q);
When I execute it this way, it fails and I always get this warning: Warning: First argument is not an array in
(the line where the execution is)
When I try to execute it using raw SQL (as the example in the documentation says) like:
$q = "UPDATE top_banners SET top_banners.banner_id = NULL WHERE top_banners.banner_id NOT IN (SELECT banners.id FROM banners)";
$top = new \Main\Models\TopBanners();
$result = new \Phalcon\Mvc\Model\Resultset\Simple(null, $top, $top->getReadConnection()->query($q));
The query is successful, but it still produce the error: PDOException: SQLSTATE[HY000]: General error
(for the execution line)
Phalcon debug:
0 PDOStatement->fetchAll()
1 Phalcon\Db\Result\Pdo->fetchAll()
2 Phalcon\Mvc\Model\Resultset->__construct(Object(Phalcon\Db\Result\Pdo), null)
3 Phalcon\Mvc\Model\Resultset\Simple->__construct(null, Object(Main\Models\TopBanners: ), Object(Phalcon\Db\Result\Pdo)) >> IT FAILS HERE
4 Main\Controllers\Admin\UsersController->deleteAction(12)
5 Phalcon\Dispatcher->dispatch()
6 Phalcon\Mvc\Application->handle()
But when I just execute it without Resultset, everything works fine, successful update, no warnings, no errors:
$q = "UPDATE top_banners SET top_banners.banner_id = NULL WHERE top_banners.banner_id NOT IN (SELECT banners.id FROM banners)";
$top = new \Main\Models\TopBanners();
$result = $top->getReadConnection()->query($q);
So what the hell is going on here? Why does it refuse to execute the query with the ModelsManager? And why does it output general error when the query is successfully executed? I'm trying to undersatnd but I'm confused...
Thanks in advance for your ideas.