Skip to content

ActiveRow problem with update of primary key #57

@mdjimy

Description

@mdjimy

Hi,
recently, I've been exploring source code of some database entities and I've noticed, that in method update of object ActiveRow is one small bug. Well to be precise, it's not a bug, but I think It's not a valid behavior of method too.

The code of method looks like this:

public function update($data) {
    $selection = $this->table->createSelectionInstance()->wherePrimary($this->getPrimary());
    if ($selection->update($data)) {
        selection->select('*');
        if (($row = $selection->fetch()) === FALSE) {
            throw new Nette\InvalidStateException('Database refetch failed; row does not exist!');
        }
        $this->data = $row->data;
        return TRUE;
    else {
        return FALSE;
    }
}

How you can see, if I’ll be updating primary key of ActiveRow, the primary key will be in database updated (if I don’t have defined any references on it), but I’ll end up with an exception “Database fetch failed;…” because in the query is used an old value of the primary key.

I think that a better behavior this method will be the one from below:

  1. To disable update of a primary column(s), and throw an exception before update in DB
  2. Or to fetch updated row for from DB on updated key (my option)

If you don't have anything against this, I'd like to resolve this issue & create pull request. (Because this term at school I have a subject called Open-Source Programming in which I have to join some running open source project & resolve some issues.) :D

Thanks for your attention,
and I'll look forward to your reply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions