ZF-4166: findParentRow fails when foriegn key is null


Using the examples from the manual for fetching parent rows which uses the example database, the following code will result in a SQL error when the reported_by field is null for a record. Assume the DB Table classes are set up exactly as they are in the manual.

$bugsTable = new Bugs();
$bugsRowset = $bugsTable->fetchAll(array('bug_status = ?' => 'NEW'));
$bug1 = $bugsRowset->current();

$reporter = $bug1->findParentRow('Accounts', 'Reporter');

When the reported_by field is null, the generated Statement does not get any values bound to it which results in a where statement similar to "where account_name = ?" with no parameters to bind to the question mark. With a MySQLi adapter the error says: Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : No data supplied for parameters in prepared statement in ... library/Zend/Db/Statement/Mysqli.php on line 215

Expected Behavior: I would expect any of the following options: * generate an exception about having a null value in the foreign key column. * gracefully fail similar to the result returned from something like $bugsTable->find('bogus'). * correctly bind a null value and execute the query and hope for the best.


I did run into the same exception. With a {{pdo_mysql}} adapter, the message is: {quote} exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' in [...]library\Zend\Db\Statement\Pdo.php:238 {quote}

I disagree with Grady Kuhnline about generating an exception to warn about a {{null}} value in the foreign key column: why would it be an error?

What I would expect is {{Zend_Db_Table_Row_Abstract::findParentRow()}} to return {{null}} (no parent found). So an Exception could be thrown by {{Zend_Db_Statement_Pdo}} and caught by {{Zend_Db_Table_Row_Abstract::findParentRow()}} for it to be aware there is no parent on that Row.

It seems to duplicate ZF-3347