ZF-3114: Zend_Db_Table_Row_Abstract-->__set() modified detection
Description
I'm just gonna give an example. Please delete/close this if I'm wrong.
my current code:
if($photo->albumId != $albumId) $photo->albumId = $albumId;
if($photo->name != $name) $photo->name = $name;
$photo->save();
better code:
$photo->albumId = $albumId;
$photo->name = $name;
$photo->save();
fix required: in Zend_Db_Table_Row_Abstract old:
public function __set($columnName, $value)
{
$columnName = $this->_transformColumn($columnName);
if (!array_key_exists($columnName, $this->_data)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
}
$this->_data[$columnName] = $value;
$this->_modifiedFields[$columnName] = true;
}
new:
public function __set($columnName, $value)
{
$columnName = $this->_transformColumn($columnName);
if (!array_key_exists($columnName, $this->_data)) {
require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
}
if($this->_data[$columnName] != $value) {
$this->_data[$columnName] = $value;
$this->_modifiedFields[$columnName] = true;
}
}
This is not tested. Just to make clear what I want.
version: trunk 9228
// edit: made code readable // edit2: second attempt :D
Comments
Posted by Wil Sinclair (wil) on 2008-04-18T13:20:28.000+0000
Please evaluate and categorize as necessary.
Posted by Darby Felton (darby) on 2008-04-21T12:33:16.000+0000
This is not an issue; if you examine the code of {{_doUpdate()}}, you'll see that this functionality already exists. For example:
/** * Compare the data to the modified fields array to discover * which columns have been changed. */ $diffData = array_intersect_key($this->_data, $this->_modifiedFields);Please feel free to reopen if I have missed something. :)
Posted by Alexander Lanin (alexl) on 2008-04-21T14:00:05.000+0000
array_intersect_key() does not evaluate the value at all. I just checks the keys. http://de.php.net/manual/en/…
and ``` is just "true" anyway
so I think whats happening is that doUpdate updates all fields, even if value was "changed" but remains the same.
maybe you didn't understood my point. I was saying that when sql returns me a "name=fritz" and I do tableRow->name = "fritz" than I did not change the value - no need to include it into doUpdate()
Posted by Darby Felton (darby) on 2008-04-21T14:05:08.000+0000
I see now; thanks for clarifying this. :)
Posted by Mickael Perraud (mikaelkael) on 2008-12-08T05:01:59.000+0000
It's a little more complicated than a simple '!='. For example, we must differently manage 'null', '', 'false' and '0'.
Posted by Alexander Lanin (alexl) on 2008-12-08T09:10:37.000+0000
!== ;-)
Posted by Mickael Perraud (mikaelkael) on 2008-12-08T09:45:12.000+0000
See http://mikaelkael.fr/ZF-3114.php for a first try. We must read by lines (not by columns).
Posted by Rob Allen (rob) on 2012-11-20T20:52:30.000+0000
Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".
Feel free to re-open and provide a patch if you want to fix this issue.