Cakephp を使い始めましたが、解決できない問題に遭遇しました。
関連する次のモデル関係があります。
演習 hasMany Points Student hasMany Points,
今度は、すべての演習にポイント データ セットがあるかどうか、studentsController をチェックインし、新しいデータ セットを挿入しないようにしたいと考えています。
ポイント データセットがない状態で開始すると、関数は最初の正しい演習用に新しいポイント データセットを追加しますが、その後、新しいデータセットを作成する代わりに、このデータセットの erxercise_id のみを更新します。
コントローラー関数は次のようになります。
public function correct($id = null) {
$this->Student->id = $id;
$this->Student->recursive = 2;
if ($this->request->is('get')) {
$data = $this->Student->Exam->Exercise->find('all');
foreach($data as $exercise)
{
$exerciseID = $exercise['Exercise']['id'];
$this->Student->Point->recursive = 0;
$foundPoints = $this->Student->Point->find('all', array('conditions' => array('exercise_id' => $exerciseID)));
if($foundPoints == null)
{
$emptyPoints = array ('Point' => array(
'exercise_id' => $exerciseID,
'student_id' => $id
)
);
$this->Student->Point->save($emptyPoints);
}
else{
}
}
}
else //POST
{
}
}