Issues

ZF-3355: Implement fetchPairs()

Issue Type: New Feature Created: 2008-05-30T02:08:20.000+0000 Last Updated: 2012-05-30T13:45:42.000+0000 Status: Open Fix version(s): - Next Major Release ()

Reporter: Amr Mostafa (alienbrain) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Table

Related issues: - ZF-2006

Attachments: - Zend_Db_Table_fetchPairs.patch

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.

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:

  • Zend_Loader::loadClass($this->_rowsetClass);
  • return new $this->_rowsetClass($data);
  • $rowsetClass = $this->getRowsetClass();
  • if (!class_exists($rowsetClass)) {
  • require_once 'Zend/Loader.php';
  • Zend_Loader::loadClass($rowsetClass);
  • }
  • return new $rowsetClass($data);

Posted by Ondrej Machulda (ondram) on 2012-05-30T13:45:42.000+0000

Ehm, maybe this one gets better comments:

<pre class="highlight">
-        Zend_Loader::loadClass($this->_rowsetClass);
-        return new $this->_rowsetClass($data);
+        $rowsetClass = $this->getRowsetClass();
+        if (!class_exists($rowsetClass)) {
+            require_once 'Zend/Loader.php';
+            Zend_Loader::loadClass($rowsetClass);
+        }
+        return new $rowsetClass($data);

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts