[html-formfu] HTML-FormFu-DBIC

Mario Minati mario.minati at googlemail.com
Thu Sep 27 10:32:15 GMT 2007


On Thursday 27 September 2007 10:24:58 Zbigniew Lukasiak wrote:
> 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
> http://search.cpan.org/~ash/DBIx-Class-0.08007/lib/DBIx/Class/Relationship/
>Base.pm#set_$rel ), 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.

You are removing and recreating the related rows, what do you think of a loop 
removing only records that are no longer required and create new ones.
I'm thinking of this as in my app the model (and the db) autocreates an 
GUID/UUID column for every new row that is used for linking stuff together. 
These kinds of relations would currently get lost.

BTW:
What kind of select box does MySelect provide?

With regard to your idea of separating the fill_formfu_values and 
populate_from_formfu I suggest putting the functions itself in a class in the 
HTML::FormFu tree, providing the functionallity.
Then the DBIC::HTML::FormFu class can use these functions to do it's work and 
everyone's free to go his/her way.

Greets,
Mario



More information about the HTML-FormFu mailing list