[jifty-devel] validate_column and before_create conundrum

Henry Baragar Henry.Baragar at instantiated.ca
Mon Mar 26 13:44:33 EDT 2007


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.  

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 


More information about the jifty-devel mailing list