[html-formfu] More complex DBIC/FormFu interaction

Nigel Metheringham nigel.metheringham at dev.intechnology.co.uk
Tue Aug 31 12:19:49 GMT 2010

I am attempting to put together a form that handles an intersection
between 2 different database objects.

I'll attempt to explain this in words - hopefully its clear. If not
I can get out the object definitions, but they have additional
clutter around which may make things muddier :-)

This is for a theatre backstage management system. I'm using [] to
show row objects in the description below - so [event] is the row
class/object for an event.

We have an [event] (ie a show in the theatre). An [event] has many
[booking]s (ie a hire session)

We also have a number of [staff]

I want a form to allow a particular [staff] member to volunteer for
[bookings] within a specified [event]

There is a linking table for this - [crew_volunteer] - which has a
belongs to relation to [booking] and [staff], ([staff] has many
[crew_volunteer] and many-to-many [booking] - and the same in
reverse - ie a typical linking table).

So at the point where I am generating the form I have 2 objects -
[event] and [staff]

Now if I have a YAML form config like this...
      - type: Checkboxgroup
        name: bookings
          label_column: text_info
          resultset: Booking
            order_by: start
            prefetch: booking_type
            event: 382

and use a typical Catalyst::Controller::HTML::FormFu like this:-

    # check and process form
    if ( $form->submitted_and_valid && ( lc( $form->method ) eq 'post' ) ) {
        $c->log->debug('Dealing with form to update user');
    elsif ( $form->has_errors ) {
        $c->log->debug( 'Errors in form: ' . Dumper( $form->get_errors ) );
    elsif ( !$form->submitted ) {
        $c->log->debug('Setting form default values');

That works fine, except I have hard coded the [event] I am working
with (the condition section within the model_config) - I want it to
work with the [event] that is passed to the controller. So I tried
finagling that within the first part of the code within the

    # splice event info into the form as a restriction
    my $element = $form->get_element( { name => 'bookings' } );
    my $modelcf = $element->model_config();
    $modelcf->{condition} = { event => $event->id };
    $form->process;    # need to redo this explicitly due to change above

However the FormFu Model code is not picking up the changed condition
(including if I delete the YAML condition config entirely).

Now I could entirely build the element within the perl controller
code - I have used that elsewhere for where its a non-database type
form - but I'm starting to embed presentation and config into the

So how can I add a dynamic restriction to a database many-to-many
select form? Is there a much cleaner mechanism I should be using?
Can I just override the caching that appears be taking part within
this element?

[ Nigel Metheringham             Nigel.Metheringham at InTechnology.com ]
[ - Comments in this message are my own and not ITO opinion/policy - ]

More information about the HTML-FormFu mailing list