Cakephp3 クエリビルダで困ってます。
informationsテーブルにはcase・categoryの2つのテーブルが「多 対 1」の関係でリレーション
informations_usersテーブルでは「多 対 多」でリレーションしています。
CREATE TABLE `informations` ( `id` int(11) NOT NULL, `title` varchar(255) NOT NULL COMMENT '件名', `content` text NOT NULL COMMENT '内容', `case_id` int(11) NOT NULL COMMENT 'INFO_案件ID', `category_id` int(11) NOT NULL COMMENT 'INFO_カテゴリーID', `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT; CREATE TABLE `informations_users` ( `information_id` int(11) NOT NULL, `users_id` int(11) NOT NULL, `read_flag` varchar(255) NOT NULL COMMENT '既読ステータス' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
実装したい検索フィルターは、
・title検索(inputbox)
・案件検索(selectbox)
・カテゴリー検索(selectbox)
・既読ステータス検索(selectbox)
上記、4つです。
$informations = $this->Informations->find() ->contain(['Cases', 'Categories', 'Users']) ->where([ 'Informations.title like' => $this->request->data('title'), 'Informations.projectcase_id' => $this->request->data('case_id'), 'Informations.projectcase_id' => $this->request->data('category_id'), ]) ->matching('Users', function($q){ $person_id = $this->request->session()->read('Auth.User.id'); $data = $this->request->data('users')[0]['_read_flag']; return $q ->where([ 'InformationsUsers.user_id' => $person_id, 'InformationsUsers.read_flag' => $data, ]); });
上記コードではエラーが発生してしまいました。
if文ですべてのパターンを書かない方法を教えてください。
よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー