[html-formfu] Example code for enforcing unique column value

Ascii King tech at swattermatter.com
Thu Jun 4 16:16:05 GMT 2009


Does anyone have some example of the code they use to enforce a unique 
value in a column using Catalyst and FormFu? I have the database set up 
to not allow duplicate values, but I don't know if it's unique until I 
get the error back. This can't be the way.

I am sort of assuming that I would need a transformer on an element that 
takes the value and runs a query against the database to see if it is 
there or not? I'm not sure how that code would work or if it is even the 
right way to go about it.

    transformers:
        - type: Callback
          callback: MyApp::Utils::is_unique


sub is_unique {
    my ( $value, $field_value ) = @_;

    return $c->model(__PACKAGE__)->find({username=>$field_value}) ? 0:1;
}




More information about the HTML-FormFu mailing list