어떤 이유로 cakePHP에서 하나의 결과 2 부를 제공합니다. 아무도 왜 그것을 고칠 지 말해 줄 수 있습니까? 지금은 큰 문제는 아니지만 한 명의 플레이어에 대해 여러 개의 playgroup을 얻으면 파일 다운로드 크기가 늘어납니다.cakePHP가 중복 레코드를 반환했습니다
$this->recursive = -1;
return $this->find('all', array(
'order' => array(
'PlaygroupActivity.timestamp DESC'
),
'limit' => $limit,
'joins' => array(
array(
'table' => 'playgroup_players',
'alias' => 'PlaygroupPlayers',
'type' => 'inner',
'foreignKey' => false,
'conditions'=> array('PlaygroupPlayers.playgroup_id = Playgroup.id', 'PlaygroupPlayers.player_id'=>$id)
),
array(
'table' => 'playgroup_activities',
'alias' => 'PlaygroupActivity',
'type' => 'inner',
'foreignKey' => false,
'conditions'=> array('PlaygroupActivity.playgroup_id = Playgroup.id')
)
),
'contain'=> array('PlaygroupActivity')
));
그리고 결과 :
{
"data":[
{
"Playgroup":{
"id":"3",
"name":"South Florida Redemption",
"email":null,
"email_username":null,
"email_password":null,
"tag":null,
"description":null,
"avatar_url":null,
"city":null,
"state":null
},
"PlaygroupActivity":[
{
"id":"3",
"text":"FINAL RESULTS OF THE FLORIDA STATE TOURNAMENT ",
"timestamp":"2011-11-02 00:13:33",
"playgroup_id":"3",
"timeSince":"1320210813000"
}
]
},
{
"Playgroup":{
"id":"2",
"name":"Redemption Springfield",
"email":null,
"email_username":null,
"email_password":null,
"tag":null,
"description":null,
"avatar_url":null,
"city":null,
"state":null
},
"PlaygroupActivity":[
{
"id":"2",
"text":"Due to bad weather, our Redemption meet today will be canceled.",
"timestamp":"2011-02-01 14:16:21",
"playgroup_id":"2",
"timeSince":"1296591381000"
},
{
"id":"1",
"text":"Remember we have a meet Tuesday, February 1rst at the Greene County Library Station at 6:30pm.",
"timestamp":"2011-01-28 23:01:57",
"playgroup_id":"2",
"timeSince":"1296277317000"
}
]
},
{
"Playgroup":{
"id":"2",
"name":"Redemption Springfield",
"email":null,
"email_username":null,
"email_password":null,
"tag":null,
"description":null,
"avatar_url":null,
"city":null,
"state":null
},
"PlaygroupActivity":[
{
"id":"2",
"text":"Due to bad weather, our Redemption meet today will be canceled.",
"timestamp":"2011-02-01 14:16:21",
"playgroup_id":"2",
"timeSince":"1296591381000"
},
{
"id":"1",
"text":"Remember we have a meet Tuesday, February 1rst at the Greene County Library Station at 6:30pm.",
"timestamp":"2011-01-28 23:01:57",
"playgroup_id":"2",
"timeSince":"1296277317000"
}
]
}
],
"status":200
}
또한 Olegs 방법은 잘 작동합니다; 내 조인 두 가지 조합을 사용하고 있습니다. –
do'h! 나는 그룹을 생각하지 않았다는 것을 믿을 수 없다 .BY! – LordZardeck
일부 MySQL 설정에서는 이것이 작동 할 수도 있지만 (작업 결과에 의해 오류가 발생하지는 않음) 정확한 쿼리가 아니며 결과가 정의되지 않았 음을 유의하십시오. GROUP BY 절에서 모든 비 집합 필드를 지정해야합니다. 이것은 또한 당신이 원하지 않는 결과를 얻지 못할 수도 있고, 어느 시점에서 그 결과를 얻지 못할 수도 있음을 의미합니다. 현재 플레이어 당 하나의 PlayGroup 만 원한다면 어느 것을 지정해야합니다! –