From 84581a61f6cd331295f8dc9f32dcb26419e02492 Mon Sep 17 00:00:00 2001 From: colinmollenhour Date: Wed, 2 Jan 2013 15:44:18 -0500 Subject: [PATCH] Use collection _idFieldName by default for toOption* methods. --- lib/Varien/Data/Collection/Db.php | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/Varien/Data/Collection/Db.php b/lib/Varien/Data/Collection/Db.php index 5c891927438f6..51642331f1ec5 100644 --- a/lib/Varien/Data/Collection/Db.php +++ b/lib/Varien/Data/Collection/Db.php @@ -607,6 +607,37 @@ public function fetchItem() return false; } + /** + * Overridden to use _idFieldName by default. + * + * @param string $valueField + * @param string $labelField + * @param array $additional + * @return array + */ + protected function _toOptionArray($valueField = NULL, $labelField = 'name', $additional = array()) + { + if ($valueField === NULL) { + $valueField = $this->getIdFieldName(); + } + return parent::_toOptionArray($valueField, $labelField, $additional); + } + + /** + * Overridden to use _idFieldName by default. + * + * @param string $valueField + * @param string $labelField + * @return array + */ + protected function _toOptionHash($valueField = NULL, $labelField = 'name') + { + if ($valueField === NULL) { + $valueField = $this->getIdFieldName(); + } + return parent::_toOptionHash($valueField, $labelField); + } + /** * Convert items array to hash for select options * unsing fetchItem method @@ -622,8 +653,11 @@ public function fetchItem() * @param string $labelField * @return array */ - protected function _toOptionHashOptimized($valueField='id', $labelField='name') + protected function _toOptionHashOptimized($valueField=NULL, $labelField='name') { + if ($valueField === NULL) { + $valueField = $this->getIdFieldName(); + } $result = array(); while ($item = $this->fetchItem()) { $result[$item->getData($valueField)] = $item->getData($labelField);