我正在尝试将 Lithiumslist
选项find()
与 SQL 一起使用DISTINCT
。我应该得到一个填充有值的数组,相反,我得到一个空数组。
这确实有意义,因为我将不同的字段作为一个字符串而不是元素数组传递,但我不知道如何在锂中使用 DISTINCT。
一些方向将不胜感激。这可能是情人节,但今天锂并没有向我表达太多的爱 :)
模型:
class ZipCodes extends \app\extensions\data\Model {
protected $_meta = array(
'key' => 'zip_code_id',
'title' => 'state_name'
);
protected $_schema = array(
'state_name' => array('type' => 'varchar'),
'StateFIPS' => array('type' => 'varchar')
//there are more fields in my table but I haven't defined the
//rest in my model
);
}
我的控制器中的 add 方法
public function add()
{
$zipcodes = Zipcodes::find('list', array(
'fields' => array('DISTINCT state_name'),
'order' => 'state_name ASC',
'conditions' => array('state_name' => array('!=' => ''))
)
);
return compact('zipcodes');
}