CakePHP2に CakeDC/Search Pluginを導入し、検索処理を作成委しています。
その検索処理の中で、重複しているレコードは 1件として表示させたいので、distinct句を追加して処理をしたいと思っていますが、どのように記述すればいいのでしょうか?
(特に集計をする必要はありませんが、distinct句が難しければ、group by句でも問題ありません。)
現在、重複したものが出てきますが、下記のような検索処理を書いています。
「category_id」が重複している場合は、そのうち 1件だけを表示したいと思っています。
そもそも、CakeDC/Search Pluginで可能なのか、可能な場合は、どのように記述するのか、お教えいただけませんでしょうか?
/app/Controller/TopicsController.php には以下のソースを記述しています。
PHP
1class TopicsController extends AppController { 2 3 public $uses = array ("Topic"); 4 public $name = "Topics"; 5 6 public $components = array('Search.Prg'); 7 public $presetVars = array(); 8 9 public $paginate = array( 10 'Topic' => array( 11 'paramType' => 'querystring', 12 'limit' => 10, 13 'order' => array('id' => 'ASC'), 14 ), 15 ); 16 17 public function admin_index() { 18 // 検索条件設定 19 $this->Prg->commonProcess(); 20 21 // 検索条件取得 22 $conditions = $this->Topic->parseCriteria($this->passedArgs); 23 24 $this->paginate["Topic"]["conditions"] = $conditions; 25 26 $this->Topic->recursive = 1; 27 $topics = $this->paginate('Topics'); 28 29 $this->set(compact('topics')); 30 } 31 32 以下略 33
/app/Model/Topic.php には以下のソースを記述しています。
PHP
1class Topic extends AppModel { 2 public $name = "Topic"; 3 4 public $actsAs = array ( "Search.Searchable" ); 5 6 public $filterArgs = array( 7 'topic_id' => array('type' => 'value', 'field' => 'Topic.topic_id', 'encode' => true), 8 'category_id' => array('type' => 'value', 'field' => 'Topic.category_id', 'encode' => true), 9 'category_name' => array('type' => 'like', 'field' => 'Topic.category_name', 'encode' => true), 10 ); 11 12 public $presetVars = array( 13 array('field' => 'topic_id', 'type' => 'value', 'empty' => true), 14 array('field' => 'category_id', 'type' => 'value', 'empty' => true), 15 array('field' => 'category_name', 'type' => 'value', 'empty' => true), 16 ); 17 18 以下略 19
あなたの回答
tips
プレビュー