On Sun, Jun 03, 2007 at 07:47:04PM +0200, Alexander Staubo wrote: > The creator of Rails is not the only developer working on Rails. There > are Rails developers who disagree with him on these issues, and "his > disciples" does not equate "the community". On the other hand, I admit > that this mindset has a negative impact on the development of Rails as > a whole. Indeed, it certainly left me with a bad taste in my mouth. > For example, part of the point of having validations declared on the > model is so that you can raise user-friendly errors (and pipe them > through gettext for localization) such as "Your password must be at > least 4 characters long and contain only letters and digits". > Databases don't support this, and so applications end up having to > duplicate data-validation logic in order to find out what kind of user > input is invalid. I think you're confusing validation and integrity constraints. The example you're giving could be implemented in either the DB or the app. Personnaly I'd do it in the app since it's something that doesn't affect the integrity of the data. If I go in and manually change someone's password to something not following that rule it's not going to affect anything. Integrity constraints are different: if you violate them your data has serious problem. They are the assumptions of your model upon which everything depends. We're talking referential integrity and uniqueness. These things *cannot* be checked reliably in the app, and you shouldn't try. You assume the constraints are valid and feel confident they are, because the database has checked them for you. > This still isn't enough for the app side -- if multiple columns fail > to validate, the app needs to know about them all, not just the first > one: Basically, validation in this case is completely orthoginal to integrity checks. If the data being validated isn't crucial to the operation of the app, I wouldn't bother putting it in the database. But fundamental integrity constraints, the database is the only place. I wish you success in your efforts to making rails a little more sane in this area. Have a nice day, -- Martijn van Oosterhout <kleptog@xxxxxxxxx> http://svana.org/kleptog/ > From each according to his ability. To each according to his ability to litigate.
Attachment:
signature.asc
Description: Digital signature