私のモデルには基本的にコードがなく、それを変更しようとしているので、ファットモデルとスキニーコントローラーを正しい方法で使用する方法についてもっと学ぼうとしています。私の関数は機能しますが、現在、2 つの find() クエリを結合しようとしていますが、そのうちの 1 つが単純な条件を持っていることを除いて、ほぼ同じに見えます。
私のモデルは次のようになります。
function pieChart() {
//Get Data for PieChart
$this->RecordDrug->virtualFields['sum'] ='COUNT(*)';
$records = array();
$records=$this->RecordDrug->find('list',
array('fields' => array( 'Drug.drug', 'sum'),
'contain' => array( 'Drug', 'Record' ),
'group' => 'Drug.Drug'
));
$this->set('output',$records);
return $records;
}
I will have two controllers using this. One of them will use this code as is, just simply call the pieChart() function. The other controller will have to see a condition that only selects the users entries. So
'conditions' => array('Record.user_id' => $this->Auth->user('id'))
これを正しい方法で行うにはどうすればよいですか?OOP の知識がかなり限られているため、これに問題があると思います。find() 関数をより効率的かつ合理的にするのに役立つ例やリソースがあれば、本当に感謝しています。