Browse Source

Merge pull request #5927 from cakephp/3.0-find-list

Rename option "idField" to "keyField".
José Lorenzo Rodríguez 11 years ago
parent
commit
6b2b9fa3fc
2 changed files with 24 additions and 10 deletions
  1. 23 9
      src/ORM/Table.php
  2. 1 1
      tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php

+ 23 - 9
src/ORM/Table.php

@@ -908,7 +908,7 @@ class Table implements RepositoryInterface, EventListenerInterface
      *
      * ```
      * $table->find('list', [
-     *  'idField' => 'name',
+     *  'keyField' => 'name',
      *  'valueField' => 'age'
      * ]);
      * ```
@@ -943,18 +943,25 @@ class Table implements RepositoryInterface, EventListenerInterface
     public function findList(Query $query, array $options)
     {
         $options += [
-            'idField' => $this->primaryKey(),
+            'keyField' => $this->primaryKey(),
             'valueField' => $this->displayField(),
             'groupField' => null
         ];
+
+        if (isset($options['idField'])) {
+            $options['keyField'] = $options['idField'];
+            unset($options['idField']);
+            trigger_error('Option "idField" is deprecated, use "keyField" instead.', E_USER_WARNING);
+        }
+
         $options = $this->_setFieldMatchers(
             $options,
-            ['idField', 'valueField', 'groupField']
+            ['keyField', 'valueField', 'groupField']
         );
 
         return $query->formatResults(function ($results) use ($options) {
             return $results->combine(
-                $options['idField'],
+                $options['keyField'],
                 $options['valueField'],
                 $options['groupField']
             );
@@ -970,12 +977,12 @@ class Table implements RepositoryInterface, EventListenerInterface
      *
      * You can customize what fields are used for nesting results, by default the
      * primary key and the `parent_id` fields are used. If you wish to change
-     * these defaults you need to provide the keys `idField` or `parentField` in
+     * these defaults you need to provide the keys `keyField` or `parentField` in
      * `$options`:
      *
      * ```
      * $table->find('threaded', [
-     *  'idField' => 'id',
+     *  'keyField' => 'id',
      *  'parentField' => 'ancestor_id'
      * ]);
      * ```
@@ -987,13 +994,20 @@ class Table implements RepositoryInterface, EventListenerInterface
     public function findThreaded(Query $query, array $options)
     {
         $options += [
-            'idField' => $this->primaryKey(),
+            'keyField' => $this->primaryKey(),
             'parentField' => 'parent_id',
         ];
-        $options = $this->_setFieldMatchers($options, ['idField', 'parentField']);
+
+        if (isset($options['idField'])) {
+            $options['keyField'] = $options['idField'];
+            unset($options['idField']);
+            trigger_error('Option "idField" is deprecated, use "keyField" instead.', E_USER_WARNING);
+        }
+
+        $options = $this->_setFieldMatchers($options, ['keyField', 'parentField']);
 
         return $query->formatResults(function ($results) use ($options) {
-            return $results->nest($options['idField'], $options['parentField']);
+            return $results->nest($options['keyField'], $options['parentField']);
         });
     }
 

+ 1 - 1
tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php

@@ -406,7 +406,7 @@ class TranslateBehaviorTest extends TestCase
         $table->addBehavior('Translate', ['fields' => ['title', 'body']]);
         $results = $table
             ->find('list', [
-                'idField' => 'title',
+                'keyField' => 'title',
                 'valueField' => '_translations.deu.title',
                 'groupField' => 'id'
             ])