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

Description

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


// 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:


// 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