repository – Should the Model be able to persist itself? When?


I might start by saying that I am aware that usually there’s a Repository layer

bookRepository.persist(book)

that abstracts the interaction with the database, but something about using the model directly feels really tempting, as in

book.persist()

This second option would also allow for the model to persist itself when changes are made, which seems pretty useful:

void updateAuthor(string newAuthor){
   this.author=newAuthor
   this.persist()
}

Assuming that it is a non relational database and its persistence logic is as simple as

bookDatabase.update(bookId,book)

Should the model know how to persist itself?

In what situations (if any) would this approach would make sense?