ZF2-502: AbstractRowGateway

Issue Type: Bug Created: 2012-08-26T01:19:17.000+0000 Last Updated: 2012-10-08T20:14:47.000+0000 Status: Closed Fix version(s): Reporter: Fernando Andre (andref) Assignee: Ralph Schindler (ralph) Tags: - Zend\Db

  • Zend_Db

Related issues: Attachments:


Hello, I'm writing to notice what seems to be an issue in AbstractRowGateway

The code bellow in line 104

<pre class="highlight">
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:

<pre class="highlight">
$row = new RowGateway("id", "supplier", $adapter);
$row->populate((array)$someRow, true);

when changing the data the call would be:

<pre class="highlight">

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

<pre class="highlight">

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.


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:

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.