Print SQL query of ORM query builder in cakephp3

Viewed 19408

How to print ORM query

$query = $articles->find('all')->contain(['Comments']);

For example print =>

SELECT * FROM comments WHERE article_id IN (comments);
3 Answers

what about $query->sql()?

$qb = $this->Person->find()->select(["id", "text" => "concat(Name,' ',Family)"])
            ->where(['id >' => 0])
            ->where($query ? ["OR" => $filters] : null)
            ->limit(10);
dd($qb->sql());

and result:

.../src/Controller/ClientController.php (line 86)
'SELECT Person.id AS `Person__id`, concat(Name,' ',Family) AS `text` FROM person Person WHERE (id > :c0 AND (Family like '%sam%' OR Name like '%sam%' OR Family like '%sam%' OR Name like '%sam%')) LIMIT 10'
Related