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

Models Managers Query Builder

Hi,

I m trying to fire raw sql quueries using this article https://docs.phalcon.io/en/latest/reference/phql.html#using-raw-sql

$where = 'iterations_id In (SELECT max(iterations_id) from ProjectsIterationTeams where project_id=49681) ';

       $worklenz = $this->modelsManager->createBuilder()
                ->from(array('ProjectsIterationTeams'))
                ->where($where)
                //->limit($limit)
                ->getQuery()
                ->execute();

        var_dump($worklenz);

but I am getting the following error

protected 'message' => string 'Syntax error, unexpected token SELECT, near to ' max(iterations_id) from ProjectsIterationTeams where project_id=49681) ', when parsing: SELECT [ProjectsIterationTeams].* FROM [ProjectsIterationTeams] WHERE iterations_id In (SELECT max(iterations_id) from ProjectsIterationTeams where project_id=49681) (166)' (length=309) private 'string' (Exception) => string '' (length=0)

Even I have tried this

$phql = 'select * FROM projects_iterationteams WHERE iterations_id In (select max(iterations_id) from projects_iterationteams where project_id=49681)';

        $result = $this->modelsManager->executeQuery($phql);

        var_dump($result);

And getting Exception :-

object(Phalcon\Mvc\Model\Exception)[115] protected 'message' => string 'Scanning error before 'projects_iterati...' when parsing: select * FROM projects_iterationteams WHERE iterations_id In (select max(iterations_id) from projects_iterationteams where project_id=49681) (159)' (length=223)

How exactly we can fire subqueries , because I need a Model Object and if I m using Phql db query I am getting std object,which I don't require it.Anybody Please help...Thanks



1.2k

Thanks for Reply...But I am using version 0.9 which is pretty old and I need some way to do Is their any way that we can use something in index.php as Dependency Injection. I am not sure might be "phalcon" do u have way.By which we can use subqueries and return Model Object.

Thanks