On Sep 3, 2010, at 14:21 , Jeremy Evans wrote:
> Transforming database constraints into validations is possible, but
> not an easy problem to solve. In most cases, it would involve parsing
> SQL, which Sequel has a policy against doing. Even if the constraints
> could automatically be turned into validations, there's still the
> issue of presenting nice error messages to the user (other than just
> "is invalid"). Finally, I think it would create a maintenance
> burden. I think this type of code is best left to an external plugin.
I would agree with this generally. I don't mind Sequel not trying to
automatically detect constraints as a general class. For one thing, not all
constraints are CONSTRAINTs. Triggers and custom data types also work to
constrain data, as do views and stored procedures. I created
However, I was specifically surprised that Sequel wasn't willing to save me
some coding by automatically constructing "validates_presence" information.
This only needs it to use information it *already has,* with no further dialog
with the database. And if I haven't bothered to include "not null" constraints
in my database schema, or if a particular database doesn't support that, then
Sequel is off the hook; I'll have to provide those validations explicitly.
Hmmm. OK, well, maybe I take all that back. I don't know if Sequel also has
information about if there's a Default defined for a column. If I have a model
instance with some nils that correspond to columns that are Not Null but also
have a default, then I would expect that instance.valid? to be true.
Fine, fine, I'll just code the validations in by hand. {shake head ruefully}
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.