Re: Better handling of constraint failures?

[prev] [thread] [next] [Date index for 2004/08/12]

From: Clayton L. Scott
Subject: Re: Better handling of constraint failures?
Date: 20:01 on 12 Aug 2004
On Thu, 12 Aug 2004, Clayton L. Scott wrote:

> On Thu, 12 Aug 2004, Drew Taylor wrote:
>
> > Clayton L. Scott wrote:
>
> > > #Film->constrain_column(year => qr/\d{4}/);
> > > Film->constrain_column(year => [ 'Year must be four digits' => qr/\d{4}/]);
> >
> > Hmmm, I somehow overlooked this method. I've always just used
> > add_constraint(). I do think having a nice error message to report back
> > to the user is a good thing. The problem with the syntax you propose
> > above is that constrain_column() currently takes a regex or arrayref of
> > valid values. Seems like the code would be ugly to check if the 2nd
> > valid value is a regex.
>
> What I'm prosing here is a new, backwards incompatible syntax for
> constrain_column that allows you to:
>
> + add multiple constraints in one call
> + specify a verbose message upon failure
> + specify the constraint as REGEXP, CODE or ARRAY

Actually I'd change the syntax to be

Film->constrain_column(year => {'Year must be four digits'
                                  => qr/\d{4}/,
                                'Year cannot be before 1960'
                                  => sub { shift < 1960 ? 0 : 1 },
                                }
                      );


Clayton

Re: Better handling of constraint failures?
Drew Taylor 17:27 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 19:29 on 12 Aug 2004

Re: Better handling of constraint failures?
Drew Taylor 19:54 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 19:53 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 20:01 on 12 Aug 2004

Re: Better handling of constraint failures?
Perrin Harkins 19:51 on 12 Aug 2004

Re: Better handling of constraint failures?
Daniel Collis Puro 20:01 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton L. Scott 20:04 on 12 Aug 2004

Re: Better handling of constraint failures?
Daniel Collis Puro 20:42 on 12 Aug 2004

Re: Better handling of constraint failures?
Clayton Scott 21:49 on 12 Aug 2004

Re: Better handling of constraint failures?
Tony Bowden 13:52 on 24 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52