Using DISTINCT in a CakePHP find function

后端 未结 12 2052
情歌与酒
情歌与酒 2020-12-06 05:54

I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list.

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 06:23

    Using SQL grouping will also produce a distinct list. Not sure of the negative consequences if any, but it seems to work fine for me.

    $first_names = $this->Person->find('list', array(
        'fields' => 'first_name',
        'order' => 'first_name',
        'group' => 'first_name',
        'conditions' => array('Person.status' => '1'),
    ));
    $this->set('first_names', $first_names);
    

提交回复
热议问题