yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

BaseActiveRecord save method behaviour

Open zebraf1 opened this issue 1 year ago • 1 comments

When calling save() on a model object, it hints that it returns true or false whether save succeeded. It does not hint any exceptions are thrown, however it calls insert() or update() which can throw db\Exception or Throwable. So when the database configuration is wrong or database is not responsing then an Exception is thrown from save() and causes an unexpected error.

Either: a) the exceptions should be caught within save(), logged and returns false b) PHP doc for save() needs to be updated with [at]throws statement, so IDE's can detect it needs exception handling

zebraf1 avatar Feb 02 '24 10:02 zebraf1

Solution b) is preferred. Could you make a pull request?

samdark avatar Feb 09 '24 20:02 samdark