Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are several possibilities, how would you achieve such thing, it really depends on your situation, application business logic etc. (Also, you should specify Doctrine branch, 1.x or 2.x)</p> <ol> <li><p>It's integrity constraint, do it at database level: Say you have a preUpdate trigger on your table, which would either raise exception (only some DBs can do that, think Postgres, Oracle) or do nothing, just stop the update operation.</p></li> <li><p>As @jensgram suggested, you could override the validator method, and either return invalid state, or you might throw an exception, because this is not a validation problem as it is integrity and logic constraint, IMHO</p></li> <li><p>Use preSave method, either skip the save (but user won't notice a thing) or again, throw Exception from it.</p></li> <li><p>In your application, you should not allow the user to get into this situation at all. Your GUI should be explicit and clearly display that invoice is closed and cannot be modified further.</p></li> </ol> <p>Personally, I would use this scenario: First, solution No. 4, don't allow the user to do it. To be on the safe side, implement a trigger directly in the database, to prevent a bug in my application from changing closed invoice, but do it silently, no errors raised, just skip the save operation (solution No. 1). This approach has one more advantage. If you find yourself in the situation, when you need to connect to the database from any other application, that integrity constraint will be preserved.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload