如果在从数据库中删除行后调用Zend_Db_Table_Row_Abstract上的refresh()会发生什么?

时间:2013-04-05 10:40:41

标签: zend-framework zend-db-table

我正在使用Zend Framework版本1.x

refresh Zend_Db_Table_Row_Abstract方法的文档只说:

Refreshes properties from the database.

我的问题是,如果在此期间从数据库中删除了行(即通过其他一些进程),此方法将返回什么内容?

是否可以通过返回null或抛出异常来处理这种情况?

谢谢, 雅各布

1 个答案:

答案 0 :(得分:1)

首先resfresh()只调用_refresh(),如果$row === null返回Exception

protected function _refresh()
    {
        $where = $this->_getWhereQuery();
        $row = $this->_getTable()->fetchRow($where);

        if (null === $row) {
            require_once 'Zend/Db/Table/Row/Exception.php';
            throw new Zend_Db_Table_Row_Exception('Cannot refresh row as parent is missing');
        }

        $this->_data = $row->toArray();
        $this->_cleanData = $this->_data;
        $this->_modifiedFields = array();
    }