2

I'm trying to use Lithiums list option with find() along with SQL's DISTINCT. I should get an array populated with values, instead, I'm getting an empty array.

This does make sense since I'm passing in the distinct fields as one string instead of an array of elements but I don't know how else to use DISTINCT in Lithium.

Some direction would be greatly appreciated. It may be valentines day but Lithium is not showing me too much love today :)

Model:

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
    );
}

The add method in my controller

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');
}
Housni
  • 963
  • 1
  • 10
  • 23
  • I'm not 100% sure, but I don't think li3 supports putting SQL expressions in the `fields` array. At least, I've never gotten it to work... – benzado Feb 15 '12 at 19:09
  • Yeah, it doesn't look like it does, after looking at a bit of the source. Pity though, this would be really useful to have. – Housni Feb 15 '12 at 22:23
  • Check this question too ... http://stackoverflow.com/questions/13310832/get-distinct-records-from-mongodb-using-lithium – Nilam Doctor Nov 20 '12 at 18:32

0 Answers0