[html-formfu] Re: constraints_from_dbic

Carl Franks fireartist at gmail.com
Fri Mar 13 10:41:10 GMT 2009


2009/3/13 Moritz Onken <onken at houseofdesign.de>:
>
> Am 13.03.2009 um 11:09 schrieb Carl Franks:
>
>> 2009/3/13 Ian Wells <ijw at cack.org.uk>:
>>>
>>> 2009/3/10 Ian Wells <ijw at cack.org.uk>:
>>>>
>>>> I thought the HTML::FormFu::ObjectUtil::constraints_from_dbic method
>>>> might be a good idea to reduce the number of times I have to state the
>>>> length of character fields (an old favourite for inconsistencies).
>>>> But it appears to be suffering from bitrot - specifically,
>>>>
>>>>   if ( $type =~ /(char|text|binary)\z/ && defined $info->{size} ) {
>>>>
>>>> doesn't match the type of varchars coming from DBIx::Class, which is
>>>> {data_type => "character varying"}.
>>>
>>> OK, the data_type name came out of the DBIX::Class schema dumper, run
>>> on a Postgres database.  (The schema it produced wasn't portable.)
>>> I've fixed the schema to use more portable data types (varchar,
>>> specifically), which should stop the above problem happening.
>>
>> Ok, though it's probably reasonable for us to support "character varying".
>> I would agree that constraints_from_dbic() has suffered from bitrot.
>>
>> It probably should be moved into HTML::FormFu::Model::DBIC.
>>
>> Ideally, I'd like to factor out the FORM <=> DBIC logic from both
>> update() and default_values()
>> into a more reusable form that can be shared between them and
>> constraints_from_dbic(),
>> so it will gain support for relationships.
>>
>> It's not a trivial job though, and I've never had time to tackle it.
>>
>
> Hey Carl,
>
> just had a good idea. DBIC supports to pass complex hashes to create or
> update.
> We could try to use Model::HashRef and pass that hash to create or update.

Certainly, update() is different, needing a FORM => DBIC translation,
whereas both default_values() + constraints_from_model() could share a
common DBIC => FORM translation.

Though, I don't think it would buy us much to change update() to pass
everything at once as a hashref,
it does need to walk the DBIC tables/relationships itself to figure
out what the form is intended to represent, so it's not much trouble
to update each row as we walk it.

And there are a lot of Model-DBIC -specific options that we need to
handle, outside of $form->process().
I've committed my recent changes / deprecations to svn, but am still
updating the documentation, which is why I haven't "officially"
announced them yet.

Carl



More information about the HTML-FormFu mailing list