Closed maxgu closed 7 years ago
on page 219 your code:
class SqlPostRepository implements PostRepository { // ... public function save(Post $aPost) { $sql = 'INSERT INTO posts (id, body, created_at) VALUES (:id, :body, :created_at)'; $this->execute($sql, [ 'id' => $aPost->id()->id(), 'body' => $aPost->body()->content(), 'created_at' => $aPost->createdAt()->format(self::DATE_FORMAT) ]); } //... }
What if $aPost already exists? How SqlPostRepository must handle this and execute UPDATE instead INSERT?
$aPost
SqlPostRepository
UPDATE
INSERT
Thanks! I have added a comment in the code and a paragraph explaining in more detail such approach.
on page 219 your code:
What if
$aPost
already exists? HowSqlPostRepository
must handle this and executeUPDATE
insteadINSERT
?