環境
CakePHP 3.5
前提
posts hasMany commentsの関係とする
やること
postsは昇順、commentsは降順でデータを取得する
PostsController.php
<?php
namespace App\Conttoller;
class PostsController extends AppController
{
/*
* index method
*/
public function index()
{
$posts = $this->Posts->find()
->contain([
'Comments' => [
'sort' => [
'id' => 'DESC'
]
]
])
->order([
'id' => 'ASC'
]);
}
}