Search code examples
sqlzend-frameworkzend-dbzend-db-tablesql-function

Applying a SQL function on Zend_Db_Table_Row::save()


Is it possible, when saving a Zend_Db_Table_Row, to make ZF apply a SQL function on one column?

For example, if $row->save() generates by default this SQL query:

UPDATE table SET field = ? WHERE id = ?;

I would like it to automatically apply the GeomFromText() function on this field:

UPDATE table SET field = GeomFromText(?) WHERE id = ?;

Thanks for any hint on how to do this with Zend_Db!


Solution

  • Define a custom update method in your class that inherits from Zend_Db_Table (not from the Zend_Db_Table_Row) and use a Zend_Db_Expr to set the column to the function return value.

    See the docs here: http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.extending.insert-update.