I try to make universal update / swap which would always switch active status. In SQL is simple:
UPDATE contacts SET active = ABS( active - 1 ) WHERE id = ....
Where active is small int / flag 0 or 1, so it always work.
When I try to implement it to model class extend Zend_Db_Table:
public function disableContact( $contact_id )
{
$where = $this->getAdapter( )->quoteInto( 'id = ?', $contact_id );
$data = Array( );
$data ['active'] = '(ABS( the.contacts.active - 1 ))';
return parent::update( $data, $where );
}
I got Error: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "(ABS( the.contacts.active - 1 ))"<p><pre>#0 ......./ZendFramework-1.11.0/library/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
How to pass ABS expression to update ?
Use a
Zend_Db_Expr, egThe best example I can find in the manual is for inserting data but the concept is the same. See http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.insert
FYI Only
Zend_Db_Selectrecognises values wrapped in parentheses and treats them as expressions.