ZF-3355: Implement fetchPairs()
Description
Fetching key => value pairs is a common need for every one. Zend_Db_Adapter_Abstract has a convenient fetchPairs() method, and this issue aims to add even more convenient support for this in Zend_Db_Table.
Fetching key => value pairs is a common need for every one. Zend_Db_Adapter_Abstract has a convenient fetchPairs() method, and this issue aims to add even more convenient support for this in Zend_Db_Table.
Comments
Posted by Amr Mostafa (alienbrain) on 2008-05-30T02:11:21.000+0000
A patch is attached. It works exactly the same as fetchAll(), but it accepts an extra parameter (the first) which has to be an array of the 2 column names.
Posted by Martin Mayer (martin.mayer) on 2008-06-01T03:12:59.000+0000
Usage of $where, $order, $count and $offset parameters to modify the query is depracated in fetchRow() and fetchAll() methods. Wouldn't it make sense for new method to allow passing only Zend_Db_Table_Select instance as no BC break can happen?
Posted by Wil Sinclair (wil) on 2008-06-01T13:00:16.000+0000
Please assign and categorize as necessary. I've already targeted a release, but please update if that schedule is not realistic.
Posted by Amr Mostafa (alienbrain) on 2008-06-07T09:04:04.000+0000
I totally agree with Martin, but that's in the case it will be scheduled for next Major release. (Which is how it's scheduled now).
But if it's going to be in the next minor release, then IMO it should try to be consistent with the rest of the usual fetch* API. Otherwise it would feel like PHP, have to go look up the manual every time... :P
I've attached a patch which accepts Zend_Db_Table_Select instances only.
Posted by Ondrej Machulda (ondram) on 2009-12-11T12:52:44.000+0000
Working patch is ready for over a year, but not yet in upstream :-( ? This method is quite handy in many cases (e.g. adding multi options to zend_form_element_select), and current state force developers to apply this patch on their own extended classes, or break the zend_db_table paradigm and use directly zend_db->fetchPairs()...
So please, if this patch is ok, would be possible to merge it into zend_db_table?
Posted by Ondrej Machulda (ondram) on 2012-05-30T13:42:01.000+0000
BTW, instead of direct access to $this->_rowsetClass, the getter class should be used, like this:
Patch for Zend_Db_Table_fetchPairs.patch:
Posted by Ondrej Machulda (ondram) on 2012-05-30T13:45:42.000+0000
Ehm, maybe this one gets better comments: