Index: t/update/belongs_to_select.t =================================================================== --- t/update/belongs_to_select.t (revision 1572) +++ t/update/belongs_to_select.t (working copy) @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 4; use HTML::FormFu; use lib 't/lib'; @@ -33,3 +33,26 @@ is($note->master->id, 2); is($note->note, 'foo'); + +$form->load_config_file('t/update/belongs_to_select_two.yml'); + +$schema = MySchema->connect('dbi:SQLite:dbname=t/test.db'); + +$form->stash->{schema} = $schema; + +$rs = $schema->resultset('Master'); + +$rs->create( { id => 4 } ); +$rs->create( { id => 5 } ); + +$master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2 } ); + +$form->process( { id => 4, note => 'foo' } ); + +$form->model->create; + +$note = $schema->resultset("TwoNote")->find(1); + +is($note->id->id, 4); + +is($note->note, 'foo'); Index: t/update/belongs_to_select_two.yml =================================================================== --- t/update/belongs_to_select_two.yml (revision 0) +++ t/update/belongs_to_select_two.yml (revision 0) @@ -0,0 +1,8 @@ +--- + model_config: + resultset: TwoNote + elements: + - name: two_note_id + - name: note + - name: id + type: Select \ No newline at end of file Index: t/lib/DBICTestLib.pm =================================================================== --- t/lib/DBICTestLib.pm (revision 1572) +++ t/lib/DBICTestLib.pm (working copy) @@ -73,6 +73,16 @@ $dbh->do( <do( < "INTEGER", is_nullable => 0, }, + rating => { + data_type => "INTEGER", + is_nullable => 1, + } ); __PACKAGE__->set_primary_key( "user", "band" ); Index: lib/HTML/FormFu/Model/DBIC.pm =================================================================== --- lib/HTML/FormFu/Model/DBIC.pm (revision 1572) +++ lib/HTML/FormFu/Model/DBIC.pm (working copy) @@ -883,12 +883,13 @@ my @values = $form->param_list($nested_name); my @rows; - if (@values) { - my $config = _compatible_config($field); + my $config = _compatible_config($field); - my ($pk) = $config->{default_column} - || $related->result_source->primary_columns; + my ($pk) = $config->{default_column} + || $related->result_source->primary_columns; + if (@values) { + $pk = "me.$pk" unless $pk =~ /\./; @rows = $related->result_source->resultset->search( { @@ -896,9 +897,24 @@ $pk => { -in => \@values } } )->all; } - my $set_method = "set_$name"; - - $dbic->$set_method( \@rows ); + if($config->{additive}) { + + my $relinfo = $dbic->result_source->relationship_info($name); + + $pk =~ s/^.*\.//; + + my $set_method = "add_to_$name"; + my $remove_method = "remove_from_$name"; + + foreach my $row ( @rows ) { + $dbic->$remove_method($row); + $dbic->$set_method($row, $config->{link_values}); + } + } else { + my $set_method = "set_$name"; + + $dbic->$set_method( \@rows, $config->{link_values} ); + } } } } @@ -1396,7 +1412,35 @@ model_config: default_column: foo +If you want to set columns on the link table you can do so if you add a +C attribute to C: + --- + element: + - type: Checkboxgroup + name: authors + model_config: + link_values: + foo: bar + + +The default implementation will first remove all related objects and set the +new ones (see L). +If you want to add the selected objects to the current set of objects +set C in the C. + + --- + element: + - type: Checkboxgroup + name: authors + model_config: + additive: 1 + options_from_model: 0 + +( is set to C<0> because this L will try to fetch +all objects from the result class C if C is specified +without a C attribute.) + =head1 COMMON ARGUMENTS The following items are supported in the optional C hash-ref argument Index: Makefile.PL =================================================================== --- Makefile.PL (revision 1572) +++ Makefile.PL (working copy) @@ -5,7 +5,7 @@ all_from 'lib/HTML/FormFu/Model/DBIC.pm'; requires 'DBD::SQLite'; -requires 'DBIx::Class' => '0.08106'; +requires 'DBIx::Class' => '0.08108'; # DBIx::Class 0.08106 switched from DateTime::Format::MySQL to ::SQLite # Rather than changing our prereqs depending on the installed version # of DBIx::Class, just bump the required version