ZF-21: Zend_Db_Table::find() - return values have inconsistent type

Issue Type: Patch Created: 2006-06-18T03:49:09.000+0000 Last Updated: 2007-07-05T14:43:06.000+0000 Status: Resolved Fix version(s): - 0.9.0 (17/Mar/07)

Reporter: Naoto Ishikawa (ishinao) Assignee: Bill Karwin (bkarwin) Tags: - Zend_Db_Table

Related issues: - ZF-337



Zend_Db_Table::find($val) returns Zend_Db_Table_Rowset object when count((array)$val) > 1, and returns Zend_Db_Table_Row object when count((array)$val) <= 1.

I wrote following code,

$pkeys = getPKeysWithSomeConditions(); // return array of primary key $rowset = $table->find($pkeys); // $table is instance of Zend_Db_Table foreach ($rowset as $row) { // do something }

When getPKeysWithSomeConditions() returns array contains some elements, it works well, But if $pkeys contains only one element, it doesn't work. Because $rowset is instance of Zend_Db_Table_Row not instance of Zend_Db_Table_Rowset.

Isn't it more natural it returns always Zend_Db_Table_Rowset, when Zend_Db_Table::find($val) called with $val parameter that type is array ?

I wish to change Zend_Db_Table::find() method like this,

public function find($val)
    $key = $this->_primary;
    if (is_array($val)) {
        if (count($val)) {
            $where = array(
                "$key IN(?)" => $val,
        } else {
            $where = '0 = 1';  // always false condition
        $order = "$key ASC";
        return $this->fetchAll($where, $order);
    } else {
        $where = array(
            "$key = ?" => (isset($val) ? $val : ''),
        return $this->fetchRow($where);


This article is moved from fw-general ML. And I sent CLA by fax.


Posted by Bill Karwin (bkarwin) on 2006-11-13T15:15:29.000+0000

Changing fix version to 0.8.0.

Posted by Bill Karwin (bkarwin) on 2007-01-03T23:45:37.000+0000

See also ZF-557 for another confusing behavior of the find() method. We should resolve both of these.

Posted by Bill Karwin (bkarwin) on 2007-01-05T17:06:24.000+0000

Recategorize as Zend_Db_Table component.

Posted by Bill Karwin (bkarwin) on 2007-03-15T20:25:49.000+0000

As of revision 3995, the find() method always returns an object of type Zend_Db_Table_Rowset_Abstract.

Have you found an issue?

See the Overview section for more details.


© 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.