概要
アソシエーション先のテーブルに SoftDelete プラグインが設定されている場合、
連結条件には ~ JOIN Articles ON Articles.deleted IS NULL
が付加される。
下記のように記述すると論理削除済みの Articles も含めて取得できる。
Model
class ArticlesTable extends Table
{
/* 論理削除設定 */
use SoftDeleteTrait;
protected $softDeleteField = 'deleted';
}
Controller
class RecipesController extends AppController
{
/**
* {@inheritDoc}
*/
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
// モデルのロード
$this->loadModel('Articles');
}
public function index()
{
// 論理削除を含めて取得
$this->Articles->find('all', ['withDeleted']);
}
public function index2()
{
// アソシエーション先の論理削除を含める
$this->Recipes->find()
->where(['column' => 'condition'])
->contain(['Articles' => function ($q) {
return $q->find('all', ['withDeleted']);
}]);
}
}