AbstractRowGateway #2544

zfbot opened this Issue Sep 28, 2012 · 4 comments


None yet

4 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-502
Issue Type:Bug


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->data = $rowData;
        if ($rowExistsInDatabase == true) {
        } 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:


The issue is that if you do this the second call will clear the primary Key fields


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,

PS: The Unknown macro seems to be a issue of the parser in this wiki system.

zfbot commented Sep 28, 2012

(Originally posted by: ralphschindler on 08/27/12)

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.

zfbot commented Sep 28, 2012

(Originally posted by: odnanref on 08/29/12)

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.


zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at

Known GitHub users mentioned in the original message or comment:
@odnanref, @ralphschindler


@odnanref so your problem is related to a "edit" form, if i'm right.

Easy solution:

$dataFromDb = array(...)
$dataFromPost = array(...)

//Overwrite with provided post data
$data = array_merge($dataFromDb, $dataFromPost);

You still want it inside the class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment