ZF2-502: AbstractRowGateway
Description
Hello, I'm writing to notice what seems to be an issue in AbstractRowGateway
The code bellow in line 104
public function populate(array $rowData, $rowExistsInDatabase = false)
{
$this->initialize();
$this->data = $rowData;
if ($rowExistsInDatabase == true) {
$this->processPrimaryKeyData();
} else {
$this->primaryKeyData = null;
}
return $this;
}
When called to populate the object with existing data from the database the call is:
$row = new RowGateway("id", "supplier", $adapter);
$row->populate((array)$someRow, true);
when changing the data the call would be:
$row->populate((array)$someformValues);
The issue is that if you do this the second call will clear the primary Key fields
$row->populate((array)$someformValues);
So, my point is that the else block should be removed from this. If a new row is to be created or the value cleared the "user" should insert new values.
Best regards, FR
PS: The Unknown macro seems to be a issue of the parser in this wiki system.
Comments
Posted by Ralph Schindler (ralph) on 2012-08-27T20:11:10.000+0000
populate() is not really for "changing data". As you can see, $this->data = $rowData; every time populate is called. If you want to change data (from an array), we really need a separate method for that, or alter the data row-by-row via the object or array interface for the object.
Posted by Fernando Andre (andref) on 2012-08-30T00:01:02.000+0000
Ok, your correct.
But then can we just add a new method for this...
public function setFromArray(array $newData ) { foreach ($newData as $k => $v ) { if (array_key_exists($k, $this->data)){ $this->data[$k] = $v; } } return $this; }
This is copying a method from ZF1 not sure if it's exactly like this in zf1. Anyway just talking.
BR, André
Posted by Ralph Schindler (ralph) on 2012-10-08T20:14:47.000+0000
This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2544