$swimmer = $this->Swimmer->find('list', array(
'conditions' => array('Swimmer.group' => $this->data['Swimmer']['group_id']),
'order' => array('Swimmer.first_name ASC'),
'fields' => 'Swimmer.first_name'
));
答案 0 :(得分:7)
首先,按照Ann Pham的建议,在Swimmer模型中设置virtual field。例如:
var $virtualFields = array(
'name' => "CONCAT(Swimmer.first_name, ' ', Swimmer.last_name)"
);
然后,获取下拉列表的数据,如下所示:(假设Swimmers控制器)
$this->Swimmer->find('list', array('fields' => array('Swimmer.id', 'Swimmer.name')));
您也可以尝试在SwimmerModel中执行此操作:var $displayName = 'Swimmer.name';
(不是100%确定是否可行)。如果它确实有效,你将不需要查找中的'fields'数组。
答案 1 :(得分:0)
答案 2 :(得分:0)
另一种方法是在字段列表中即时连接字段。
例如:
$swimmer = $this->Swimmer->find('list',
array(
'conditions' => array(
'Swimmer.group' => $this->data['Swimmer']['group_id']),
'order' => array(
'Swimmer.first_name ASC'
),
'fields' => 'CONCAT(Swimmer.first_name, " ", Swimmer.first_name) AS full_name'
));