php-orm-pdo icon indicating copy to clipboard operation
php-orm-pdo copied to clipboard

bug found in Model.php

Open fer-g3 opened this issue 4 years ago • 3 comments

Hi I found an error in Model.php class. public function save($dados) { if (!isset($this->pk)) { $this->pk = 'id'; } if (isset($dados[$this->pk])) { **$this->find([$this->pk => $dados[$this->pk]]);** var_dump($this->count); exit; if ($this->count > 0) { $this->update($dados); } else { $this->create($dados); } } } The Save method always asign 1 into count variable after you saved one record into database, which cause you can't save any other record because it enters in update statement.

fer-g3 avatar Aug 02 '20 00:08 fer-g3

I resolve it by adding conditions key into the find array. So If $dados[$this->pk] is null then create a new record and if it's not null then update the current record. $this->find( ['conditions' => [$this->pk => $dados[$this->pk]] ]);

fer-g3 avatar Aug 02 '20 00:08 fer-g3

Good catch! Could you send a PR solving this issue?

arojunior avatar Aug 03 '20 11:08 arojunior

what's a PR? Best Regards

fer-g3 avatar Aug 04 '20 14:08 fer-g3