=over 4
-=item Arguments: (\@hashrefs | \@objs)
+=item Arguments: (\@hashrefs | \@objs), $link_vals?
=back
$actor->set_roles(\@roles);
# Replaces all of $actor's previous roles with the two named
+ $actor->set_roles(\@roles, { salary => 15_000_000 });
+ # Sets a column in the link table for all roles
+
+
Replace all the related objects with the given reference to a list of
objects. This does a C<delete> B<on the link table resultset> to remove the
association between the current object and all related objects, then calls
);
my @to_set = (ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_);
$self->search_related($rel, {})->delete;
- $self->$add_meth($_) for (@to_set);
+ $self->$add_meth($_, ref($_[1]) ? $_[1] : {}) for (@to_set);
};
my $remove_meth_name = join '::', $class, $remove_meth;
my $schema = DBICTest->init_schema();
-plan tests => 74;
+plan tests => 78;
# has_a test
my $cd = $schema->resultset("CD")->find(4);
is( $prod_rs->first->name, 'Matt S Trout',
'many_to_many add_to_$rel($obj) ok' );
$cd->remove_from_producers($prod);
+$cd->add_to_producers($prod, {attribute => 1});
+is( $prod_rs->count(), 1, 'many_to_many add_to_$rel($obj, $link_vals) count ok' );
+is( $cd->cd_to_producer->first->attribute, 1, 'many_to_many $link_vals ok');
+$cd->remove_from_producers($prod);
+$cd->set_producers([$prod], {attribute => 2});
+is( $prod_rs->count(), 1, 'many_to_many set_$rel($obj, $link_vals) count ok' );
+is( $cd->cd_to_producer->first->attribute, 2, 'many_to_many $link_vals ok');
+$cd->remove_from_producers($prod);
is( $schema->resultset('Producer')->find(1)->name, 'Matt S Trout',
"producer object exists after remove of link" );
is( $prod_rs->count, 0, 'many_to_many remove_from_$rel($obj) ok' );
is( $twokey->fourkeys_to_twokeys->count, 0,
'twokey has no links to fourkey' );
+
my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007 });
is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded');
is($undef_artist_cd->search_related('artist')->count, 0, '0=1 search when FK does not exist and object not yet in db');