Why repeat database constraints in models?
Posted
by BWelfel
on Stack Overflow
See other posts from Stack Overflow
or by BWelfel
Published on 2010-06-05T01:27:17Z
Indexed on
2010/06/05
8:52 UTC
Read the original article
Hit count: 174
In a CakePHP application, for unique constraints that are accounted for in the database, what is the benefit of having the same validation checks in the model?
I understand the benefit of having JS validation, but I believe this model validation makes an extra trip to the DB. I am 100% sure that certain validations are made in the DB so the model validation would simply be redundant.
The only benefit I see is the app recognizing the mistake and adjusting the view for the user accordingly (repopulating the fields and showing error message on the appropriate field; bettering the ux) but this could be achieved if there was a constraint naming convention and so the app could understand what the problem was with the save (existing method to do this now?)
© Stack Overflow or respective owner