[html-formfu] Automatic constraints from DBIC data types
Carl Franks
fireartist at gmail.com
Mon Oct 22 17:20:08 GMT 2007
On 10/10/2007, Zbigniew Lukasiak <zzbbyy at gmail.com> wrote:
> Hi there,
>
> I can start work on the DBIC constraints - but I am still hesitating
> about the api. I've started with a subroutine that works similarly to
> the other HTML::FormFu::DBIC subs:
>
> constraints_from_dbic( $dbic, $form );
>
> It would just scan all form fields and add the constraints from the
> $dbic row. The problem I see is with configuration - since normal
> constraints are added from the yaml config like:
>
> elements:
> - type: Text
> name: foo
> constraints:
> - type: Length
> min: 8
>
> So this would be a bit different. We could also have something like:
> elements:
> - type: Text
> name: foo
> constraints:
> - type: Length
> min: 8
> - type: From_DBIC
> dbic_field: foofoo
>
> But then when converting from a vanilla FormFu to FormFu::DBIC you
> would have to edit the whole yaml config.
>
> Hmm. Which one do you prefer? Any other api ideas?
I've just been thinking about this, and going through the archives, to
see what previous discussion there had been - and discovered that
$form already has a constraints_from_dbic() method!
I'd completely forgotten that I'd done it, and haven't even used it yet.
It creates constraints based on column_info(), for length of field,
signed and unsigned integers, and Set constraints based on an enum/set
column's list of values.
It also has basic support for relationships via:
$form->constraints_from_dbic(
$result_set,
{ column => $related_result_set }
);
See:
lib/HTML/FormFu/ObjectUtil.pm constraints_from_dbic()
t/form/constraints_from_dbic.t
t/form/constraints_from_dbic_rs.t
t/lib/Schema/Schema.pm
t/lib/Schema/Schema/Person.pm
t/lib/Schema/Schema/Dongle.pm
Has anyone used this functionality?
It's not documented, so it's probably safe to make changes if necessary.
Carl
More information about the HTML-FormFu
mailing list