Why repeat database restrictions in models?

In CakePHP, for the unique constraints that are taken into account in the database, what is the advantage of doing the same validation checks in the model?

I understand the advantage of JS validation, but I believe this model validation makes an extra trip to the database. I am 100% sure that some checks are done in the database, so checking the model is simply redundant.

The only advantage that I see is an application that recognizes an error and corrects the view for the user accordingly (re-filling the fields and displaying the error message in the corresponding field, improving ux), but this can be achieved if a restriction has been assigned and therefore the application can Understand that the problem was with persistence (existing method for doing this now?)

+3
source share
7 answers

Faster response time, less database load. The farther to the client you can do validation, i.e. JavaScript, the faster it will happen. The main con should implement the same rules in several layers.

+2
source

If the database constraints are encoded by one person and the rest of the code is code by another, they really should not fully trust each other. Check the situation at the borders, especially if they represent the boundaries of the organizational level. for example, a user to an application or one developer module to another, or one corporate department to another.

+2
source

. , . SQLite, MySQL.. , , . PostgreSQL? ? , Oracle, .

, , , , , ( , , ). , , , , .

, - ? , , CakePHP , . , DBO , .

+2

, , , - . , .

+1

CakePHP , . . , . .

+1

( , ..) , . ( ), ( , , - .

. , - , , ; .

0

@le dorfier

- - ( "-", " , - ).

, , " " ( , , RA plus TC Turing). RA ( TC) ", " ( , -/ "-" ).

, , " " , dbms ( , ) -, -.

" ". - , , -: RA, / , ?

@bradley harris.

Correctly. I would vote for you if voting were available to me. But you forget to mention that since no one can ever be sure that no other application will ever need a certain database, the only reasonable place to execute business rules is inside the DBMS.

0
source

Source: https://habr.com/ru/post/1748619/


All Articles