Issues

ZF-12101: Zend_Db_Table Check for Primary Key Doesn't First Check Table Exists

Issue Type: Improvement Created: 2012-03-16T16:58:37.000+0000 Last Updated: 2012-03-16T16:58:37.000+0000 Status: Open Fix version(s): Reporter: Zachary Schuessler (zschuessler) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db_Table

Related issues: Attachments:

Description

The _setupPrimaryKey() method in Zend_Db_Table_Abstract checks for a primary key with the following code:

<pre class="highlight">
// if no primary key was specified and none was found in the metadata
// then throw an exception.
if (empty($this->_primary)) {
    // require_once 'Zend/Db/Table/Exception.php';
    throw new Zend_Db_Table_Exception('A table must have a primary key, but none was found');
}

If you have a model setup for a table that doesn't exist, the above exception is thrown. While it's true that the primary key doesn't exist for a table that also doesn't exist, it would be nice to have a more descriptive exception like the following:

<pre class="highlight">
// Check table exists
if ( !count($this->getAdapter()->describeTable($this->_name)) ) {
    throw new Zend_Db_Table_Exception(sprintf("No table by name '%s' found", $this->_name));
}

// if no primary key was specified and none was found in the metadata
// then throw an exception.
if (empty($this->_primary)) {
    // require_once 'Zend/Db/Table/Exception.php';
    throw new Zend_Db_Table_Exception('A table must have a primary key, but none was found');
}

Comments

No comments to display

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