[html-formfu] HTML-FormFu-DBIC

Zbigniew Lukasiak zzbbyy at gmail.com
Thu Sep 27 09:24:58 GMT 2007

On 9/26/07, Mario Minati <mario.minati at googlemail.com> wrote:
> As I'm not an DBIC expert it's realy hard to get what happens when you dive
> into it, so my brain stopped following at
>         $dbic->$method( [ $objects_rs->all ] );
> Are you setting multiple User objects (for where Selectbox) for the current db
> row?
Hi  - that was for many_to_many - (see
), unfortunately for has_many currently there is no such convenient
method, and it is also not obvious how it should work.  Here is what I
did for has_many:

# 'Unrelating' all the currently related records (this is a bit of hack):
            my $info = $dbic->result_source->relationship_info($relation);
            my ($self_col, $foreign_col) = %{$info->{cond}};
            if ( $self_col =~ /^foreign/ ) {
                ( $foreign_col, $self_col ) = %{$info->{cond}};
            $foreign_col =~ s/foreign\.//;
            $dbic->$relation->update( { $foreign_col => undef } );
# Here we can also delete the records instead of 'unrelating them' -
what is correct depends
# on the application.
# I'll add an option to the config for that

            my ($pk) = $dbic->result_source->primary_columns;
            $objects_rs->update( { $foreign_col => $dbic->$pk } );

# And here relating all the records that need to be related.

# We could also add some efficiency to that - by not 'unrelating' all
of the records - only those
# that are not in @objects_rs.

Zbigniew Lukasiak

More information about the HTML-FormFu mailing list