[html-formfu] RFC: automatic constraints from DBIx::Class
column_info
Carl Franks
fireartist at gmail.com
Thu May 17 11:33:48 GMT 2007
I've added an experimental new method - constraints_from_dbic() -
which I'd like feedback on.
Is this the right way to approach getting auto-constraints for
database columns, and is the interface any good?
You can either call it with a resultset, such as...
$form->constraints_from_dbic( $schema->resultset('Table') );
Or with a schema class name and resultset class name, so that it can
be defined in a static config file...
constraints_from_dbic: [ 'MySchema', 'Table' ]
At the moment, it adds constraints to fields which have the same name
as an existing column.
I plan on adding support for a 2nd argument, which would be a hashref
mapping fields to columns (also in other related resultsets).
It currently automatically adds...
- MaxLength constraint to char/text columns with defined column_info->{size}
- Integer constraint to integer columns
- Range {min: 0} constraint to integer columns with
column_info->{extra}{unsigned} = 1
- Set constraint to enum/set columns with defined column_info->{extra}{list}
btw, the column_info->{extra} references above are standards from
SQL::Translator.
There are some examples of usage in the test files:
t/form/constraints_from_dbic.t
t/form/constraints_from_dbic_rs.t
Cheers,
Carl
More information about the HTML-FormFu
mailing list