hasMany 관계의 user_id와 일치하는 다음 코드가 있습니다. 찾은CakePHP 빈 제거 hasMany 결과
array(
(int) 0 => array(
'Scorecard' => array(
'id' => '529e400a-6e98-4471-8465-04470a0a0a0a',
'course_id' => '0a111cdd-4732-11e3-98e6-080027f3add4',
'flag_count' => '0',
'status' => '1',
),
'ScorecardsUser' => array(
(int) 0 => array(
'id' => '529e400a-8a30-4e63-b6c6-04470a0a0a0a',
'user_id' => '527d5dff-e9a0-40c0-8512-04510a0a0a0a',
'scorecard_id' => '529e400a-6e98-4471-8465-04470a0a0a0a',
'gross_score' => '50',
'points_score' => '0',
'match_score' => '0',
'handicap' => '0',
'team' => '0',
'created' => '2013-12-03 20:33:14',
'modified' => '2013-12-03 20:33:14'
)
)
),
(int) 1 => array(
'Scorecard' => array(
'id' => '52b0c20d-61e8-425d-9b8c-05d40a0a0a0a',
'course_id' => '0a111cdd-4732-11e3-98e6-080027f3add4',
'flag_count' => '0',
'status' => '1',
),
'ScorecardsUser' => array()
),
)
첫 번째 결과는 내가 예상 정확히 무엇을 다음과 같이 내가 돌아올 샘플 결과입니다. 그러나 user_id는 두 번째 것과 일치하지 않으므로 ScorecardsUser에 대한 결과는 비어 있습니다. 그러나 hasMany 모델의 조건과 일치하지 않으므로 두 번째 결과가 전혀 나오지 않아야합니까?
public function getUsersScoreCards($user_id = null) {
$this->bindModel(array(
'hasMany' => array(
'ScorecardsUser' => array(
'conditions' =>array(
'ScorecardsUser.user_id' => $user_id
)
)
)
));
$this->recursive = 1;
$this->Behaviors->load('Containable');
$contain = array('ScorecardsUser');
return $this->find('all', array('conditions' => array('Scorecard.status' => 1), 'contain' => $contain));
}
화려한 대답. 감사. 나는 항상 옵션 2를했고 그것을 싫어했다. 단지 추악했다고 생각했다. 대신 조인 방법을 조사합니다. – Mezzair