php-orm-pdo
php-orm-pdo copied to clipboard
bug found in Model.php
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.
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]] ]);
Good catch! Could you send a PR solving this issue?
what's a PR? Best Regards