Hi,
This is a quick question relating to Symfony, but could be a general MVC question.
I have a class in my model, for example, WebUser
. This class has a property of email_address
. This value must be unique to each WebUser
.
Now, I've made it so all my Symfony forms validate that the email_address
is unique for the given WebUser
, however I'm wondering if I should add this validation to the model as well?
But this also got me thinking, should you actually validate every set()
method in the model? It seems a wise enough decision to make sure no erroneous data ends up in the database, however most (if not all) data has to go through the controllers, which validate as well. So to me it seems I'm running the same validation twice and it just seems pointless?
What are your thoughts on this? I'm still leaning towards validation in the model as that makes the most sense as it dictates the business logic.
If you should validate in the model, how do you throw an appropriate set()
error in Symfony that is handled correctly by the form framework?
Thanks.