Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP 2.2.5 find('list') showing all id values as 1
    primarykey
    data
    text
    <p>In the process of upgrading a 1.3 CakePHP app to 2.2.5 and I'm getting unexpected results on a <code>find('list')</code>.</p> <p>Does anyone know why I am getting 1 for the <code>id</code> value instead of the incremental values stored in the database, which is 1,2,3,4,5?</p> <p>When I run the controller code (shown below), I get:</p> <pre><code>Array ( [1] =&gt; 5 ) </code></pre> <p>What I want to get is:</p> <pre><code>Array ( [1] =&gt; 1 (urgent) [2] =&gt; 2 [3] =&gt; 3 [4] =&gt; 4 [5] =&gt; 5 ) </code></pre> <p>And if I change it to <code>find('all')</code>, I get: <strong>*<em>Note the <code>[id]</code> value is always 1</em>*</strong></p> <pre><code>Array ( [0] =&gt; Array ( [Priority] =&gt; Array ( [id] =&gt; 1 [description] =&gt; 1 (urgent) ) ) [1] =&gt; Array ( [Priority] =&gt; Array ( [id] =&gt; 1 [description] =&gt; 2 ) ) [2] =&gt; Array ( [Priority] =&gt; Array ( [id] =&gt; 1 [description] =&gt; 3 ) ) [3] =&gt; Array ( [Priority] =&gt; Array ( [id] =&gt; 1 [description] =&gt; 4 ) ) [4] =&gt; Array ( [Priority] =&gt; Array ( [id] =&gt; 1 [description] =&gt; 5 ) ) </code></pre> <p>)</p> <p><strong>Already Tried</strong></p> <ul> <li>Renaming Priority to PriorityLevel in case Priority was a reserved word in CakePHP.</li> </ul> <p>See related code below:</p> <p><strong>Controller Code</strong></p> <pre><code>$priorities = $this-&gt;Ticket-&gt;Priority-&gt;find('list', array('fields' =&gt; array('Priority.id', 'Priority.description'),'order' =&gt; 'Priority.description')); </code></pre> <p><strong>Model Code</strong></p> <pre><code>class Ticket extends AppModel { public $name = 'Ticket'; public $belongsTo = array('Affect', 'Priority', 'User', 'Status'); public $validate = array( 'priority_id' =&gt; array( 'rule' =&gt; 'notEmpty', 'message' =&gt; 'Please assign a priority to this ticket' ) ); } class Priority extends AppModel { public $name = 'Priority'; } </code></pre> <p><strong>View Code</strong></p> <pre><code>echo $this-&gt;Form-&gt;input('Ticket.priority_id', array('type' =&gt; 'select', 'empty' =&gt; true, 'tabindex' =&gt; 2)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload