2016-09-21 18 views
0

私はcakephp3.xのクエリに問題があります。私は戻り値のデータがproject_idのように持っているようにしたいのですが、project_id内でリスト名を返します。 しかし、project_idはunique.unduplicated project_idです。 ご迷惑をおかけします。cakephpでデータを取得する3

$result = $query->find('all', [ 
         'fields' => [ 
          'project_id' => 't_project_member.project_id', 
          'project_name' => 't_project.name', 
          'member_name' => 'concat(t_member.first_name," ",t_member.last_name)' 
         ], 
         'join' => [ 
          ['table' => 't_project', 
          'type' => 'LEFT', 
          'conditions' => 't_project.id = t_project_member.project_id'], 

          ['table' => 't_member', 
          'type' => 'LEFT', 
          'conditions' => 't_member.id = t_project_member.member_id'], 

         ], 
         'conditions' => ['t_project.id' => $project_id] 
       ]); 

結果:

{ 
"result": [ 
    { 
     "project_id": 4, 
     "project_name": "Ueno Rebrand : Business cards #1", 
     "member_name": "User_3 c" 
    }, 
    { 
     "project_id": 4, 
     "project_name": "Ueno Rebrand : Business cards #1", 
     "member_name": "User_4 d" 
    }, 
    { 
     "project_id": 4, 
     "project_name": "Ueno Rebrand : Business cards #1", 
     "member_name": "User_5 e" 
    }, 
    ] 
} 

私は以下のようなデータを返したいです。

{ 
"result": [ 
    { 
     "project_id": 4, 
     "project_name": "Ueno Rebrand : Business cards #1", 
     "member_name": { 
         "User_3 c", 
         "User_4 d", 
         "User_5 e 
         } 
    }, 
    ] 
} 

ありがとうございました。

+0

project_id' 'によりグループは、の助け – Karan

+0

可能重複してもよい[CakePHPのとGROUP BY](http://stackoverflow.com/questions/2929666/cakephp-and-group-by) –

答えて

0
$result = $query->find('all', [ 
         'fields' => [ 
          'project_id' => 't_project_member.project_id', 
          'project_name' => 't_project.name', 
          'member_name' => 'concat(t_member.first_name," ",t_member.last_name)' 
         ], 
         'join' => [ 
          ['table' => 't_project', 
          'type' => 'LEFT', 
          'conditions' => 't_project.id = t_project_member.project_id'], 

          ['table' => 't_member', 
          'type' => 'LEFT', 
          'conditions' => 't_member.id = t_project_member.member_id'], 

         ], 
         'group' => '`t_project_member`.`project_id`', 
         'conditions' => ['t_project.id' => $project_id] 
       ]); 
関連する問題