[jifty-devel] validate_column and before_create conundrum

Jesse Vincent jesse at bestpractical.com
Wed Apr 18 15:26:54 EDT 2007


Henry Baragar wrote:
> Hello,
>
> I have a situation where I need to validate a column based on information from 
> other columns in the record and other records in the database.  More 
> specifically, I need to validate that (column1, column2) is unique within the 
> database.
>
> The way we started to implement this was to create a "validate_column2" which 
> looks at its own column1 to determine if the pair is unique within the 
> database.   
>   

What about throwing a validate_column1 on your ::Create action subclass?

-jesse



> This approach works well when updating column2 (and updates to column1 are not 
> allowed).  
>
> The problem arises at record creation time.  Jifty::Record calls 
> validate_column2 with the new value, but validate_column2 does not have 
> access to the value of column1 because it has not yet been stored in the 
> database.   We tried using before_create, but this gets called (by 
> Jifty::DBI::Record::create) after validate_column2 is called (by 
> Jifty::Record::create).  There are two consequences of this:  we can't find a 
> way to get access to the column1 value; and, before_create can only return a 
> status and no message (which means we can't tell the user how to fix the 
> erroneous input).
>
> Is there something we have overlooked?  How are others handling this type of 
> validation?
>
> Regards,
> Henry 
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
>
>   





More information about the jifty-devel mailing list