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');
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.