-
-
Notifications
You must be signed in to change notification settings - Fork 110
Description
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:
- To disable update of a primary column(s), and throw an exception before update in DB
- 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.