From f64b5569a69bc86b8c1a83f0215c18288376c1d5 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 19 Feb 2015 20:10:40 +0530 Subject: [PATCH] Rename option "idField" to "keyField". The latter is more intuitive. --- src/ORM/Table.php | 32 +++++++++++++------ .../ORM/Behavior/TranslateBehaviorTest.php | 2 +- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/ORM/Table.php b/src/ORM/Table.php index 72ef86dfe20..f13ed039cff 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -908,7 +908,7 @@ public function findAll(Query $query, array $options) * * ``` * $table->find('list', [ - * 'idField' => 'name', + * 'keyField' => 'name', * 'valueField' => 'age' * ]); * ``` @@ -943,18 +943,25 @@ public function findAll(Query $query, array $options) 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 @@ public function findList(Query $query, array $options) * * 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 @@ public function findList(Query $query, array $options) 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']); }); } diff --git a/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php b/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php index d695a04f656..a11f2b82c67 100644 --- a/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php +++ b/tests/TestCase/ORM/Behavior/TranslateBehaviorTest.php @@ -406,7 +406,7 @@ public function testFindTranslationsList() $table->addBehavior('Translate', ['fields' => ['title', 'body']]); $results = $table ->find('list', [ - 'idField' => 'title', + 'keyField' => 'title', 'valueField' => '_translations.deu.title', 'groupField' => 'id' ])