0
무비 테이블과 등급 테이블이 있습니다. 등급 테이블 belongsTo 영화 및 영화 hasOne 등급. "vote_count"필드를 증가시키고 싶습니다. 코드는 다음과 같습니다.Cakephp가 데이터베이스에 값을 저장 중입니다.
public function set_ratings($movieId, $value){
$this->Movie->id = $movieId;
$rateMovie = $this->Movie->read();
$oldNoOfVotes = $rateMovie['Rating']['number_of_votes'];
debug($oldNoOfVotes);
$newNoOfVotes = ++$oldNoOfVotes;
$newVoteCount = $rateMovie['Rating']['vote_count'] + $value;
$newAverageRating = $newVoteCount/$newNoOfVotes;
debug($oldNoOfVotes);
debug($newNoOfVotes);
$this->request->data['Rating']['id'] = $rateMovie['Rating']['id'];
$this->request->data['Rating']['number_of_votes'] = $newNoOfVotes;
$this->request->data['Rating']['vote_count'] = $newVoteCount;
$this->request->data['Rating']['average_rating'] = $newAverageRating;
//$this->request->data['Rating']['id'] = $rateMovie['Rating']['id'];
debug($newNoOfVotes);
$this->Movie->Rating->save($this->request->data);
debug($newNoOfVotes);
}
내가 직면하고있어 문제는 그 "vote_count는"15 말을하고 있다면 나는 그것을 증가하고 값을 디버깅하는 것은 16이지만 18로 저장지고 DB에 무엇인가가있을 때 이유?
디버그하셨습니까 ($ newVoteCount) ...? –