페이지 매김과 함께 사용되는이 사용자 지정 찾기 메서드가 있습니다. 그러나 생성하는 쿼리가 잘못되었습니다. 어떤 이유로 그것은 아무 이유없이 SELECT에 필드를 넣고 있습니다.CakePHP는 사용자 지정 페이지 매김을 할 때 잘못된 쿼리를 생성합니다.
$query['fields'] = array('COUNT(*)');
내가 gettign있어 오류가 이것이다 :
Error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous
하지만 케이크는 명백한 이유를 위해이 쿼리를 생성 난 찾기 방법의 카운트 부분을 지정하지
을SELECT COUNT(*), Country.id, State.id, ClientStatus.id, SalesStatus.id, id FROM...
내가 지금까지 발견 한 것은 배열을 포함하는 CompanyType
을 제거하면 쿼리가 작동한다는 것입니다. CompanyType
은 HABTM 연관이므로 데이터를 반환하려는 조건에는 적용하지 않습니다. Cake는 별도의 쿼리를 생성해야합니다. 그러나 어떤 접두사도없이 id
이 쿼리에 포함되는 방식을 이해하지 못합니다. :(
내가에만 카운트 세트, 다른 분야. 왜 케이크 내가이 문제를 해결하려면 어떻게해야합니까? 여기에 특히 외로운 id
을 다른 필드를 추가를 참조 $query
변수를 디버깅 할 때?
찾기 방법 :.
public function _findSearch($state, $query, $results = array()) {
$this->Behaviors->unload('Tags.Taggable');
$this->unbindModel(array(
'hasAndBelongsToMany' => array(
'Tag',
//'CompanyType'
)
), false);
if ($state === 'before') {
$query['contain'] = array(
'Country',
'State',
'SalesStatus',
'ClientStatus',
'CompanyType',
);
$query['fields'] = array(
$this->alias . '.id',
$this->alias . '.company',
$this->alias . '.company2',
$this->alias . '.company3',
$this->alias . '.street',
$this->alias . '.postal_code',
$this->alias . '.city',
$this->alias . '.selection_ranking',
$this->alias . '.role',
'Country.id',
'Country.country',
'State.id',
'State.name',
'ClientStatus.id',
'ClientStatus.name',
'SalesStatus.id',
'SalesStatus.name'
);
if (isset($query['operation']) && $query['operation'] === 'count') {
$query['fields'] = array('COUNT(*)');
//debug($query);
}
return $query;
}
if (($state === 'after') && isset($query['operation']) && $query['operation'] === 'count') {
return $results[0][0]['COUNT(*)'];
}
return $results;
}