cakephp find('list') - problem using

Posted by MOFlint on Stack Overflow See other posts from Stack Overflow or by MOFlint
Published on 2010-06-09T11:58:40Z Indexed on 2010/06/09 12:02 UTC
Read the original article Hit count: 138

Filed under:

I'm trying to get an array to poplulate a Counties select. If I use find('all') I can get the data but this array needs flattening to use in the view with $form->input($counties).

If I use find('list') I can't seem to get the right array - which is simple array of county names.

What I have tried is this:

        $ops=array(
        'conditions' => array(
            'display' => '!=0',
            'TO_DAYS(event_finish) >= TO_DAYS(NOW())'
        ),
        'fields' => 'DISTINCT venue_county',
        'order' => 'venue_county DESC'
    );
    $this->set('counties', $this->Event->find('list',$ops));

but the SQL this generates is:

SELECT Event.id, DISTINCT Event.venue_county FROM events AS Event WHERE display = 1 AND TO_DAYS(event_finish) >= TO_DAYS(NOW()) ORDER BY venue_county DESC

which generates an error because it first inserts the Event.id field in the query - which is not wanted and causes the error.

In my database I have a single table for Events which includes the venue address and I don't really want to create another table for address.

What options should I be using efor the find('list') call?

© Stack Overflow or respective owner

Related posts about cakephp