Issues

ZF-174: Documentation mistake in 'Adding Domain Logic' example

Issue Type: Docs: Problem Created: 2006-06-30T08:48:03.000+0000 Last Updated: 2008-12-19T13:44:54.000+0000 Status: Closed Fix version(s): - 0.9.1 (23/Mar/07)

Reporter: Tony Brady (tbrady) Assignee: Bill Karwin (bkarwin) Tags: - Zend_Db

Related issues: Attachments:

Description

In section 3.3.10. Adding Domain Logic an example is given of over-riding the Zend_Db_Table::update() method to automatically update a timestamp field:

<pre class="highlight">
    public function update($data)
    {
        // add a timestamp
        if (empty($data['updated_on'])) {
            $data['updated_on'] = time();
        }
        return parent::update($data);
    }

This is faulty because the parent method expects to be passed the WHERE clause for the row being updated:

<pre class="highlight">
(extract from Zend_Db_Table)

    /**
     * Updates existing rows.
     *
     * Columns must be in underscore format.
     *
     * @param array $data Column-value pairs.
     * @param string $where An SQL WHERE clause.
     * @return int The number of rows updated.
     */
    public function update(&$data, $where)
    {
        return $this->_db->update(
            $this->_name,
            $data,
            $where
        );
    }

Omitting the WHERE clause will cause a database error as an update to the primary key for all rows is attempted. The example should be changed to:

<pre class="highlight">
    public function update($data, $where)
    {
        // add a timestamp
        if (empty($data['updated_on'])) {
            $data['updated_on'] = time();
        }
        return parent::update($data, $where);
    }

Comments

Posted by Bill Karwin (bkarwin) on 2006-11-13T15:22:37.000+0000

Changing fix version to 0.8.0.

Posted by Bill Karwin (bkarwin) on 2007-01-05T17:16:05.000+0000

Recategorize as Documentation, Zend_Db.

Posted by Bill Karwin (bkarwin) on 2007-03-22T23:15:42.000+0000

The section on Zend_Db_Table was rewritten in revision 4200. The error mentioned above is now fixed.

Posted by Wil Sinclair (wil) on 2008-12-19T13:44:54.000+0000

Bookkeeping. Closing old issues and assigning them to the person who ultimately resolved the issue.

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