Showing posts with label Cake Sub Query. Show all posts
Showing posts with label Cake Sub Query. Show all posts

Friday, May 12, 2017

CakePHP 3.X Sub Query Example

$sub_query = TableRegistry::get("Test2")->find();
$sub_query->select(["count" => "SUM(Test2.score)"])
    ->where(["Test2.ref = Test1.id"]);

$query = TableRegistry::get("Test1")->find("All");
$query->select([
    "Test1.id", "Test1.name", "Test1.roll",
    "score" => $sub_query
]);

$list = $query->all()->toArray();