=over 4
-=item Arguments: (@hashrefs | @objs)
+=item Arguments: (\@hashrefs | \@objs)
=back
my @roles = $schema->resultset('Role')->search({ role =>
{ '-in' -> ['Fred', 'Barney'] } } );
- $actor->set_roles(@roles);
- # Replaces all of $actors previous roles with the two named
+ $actor->set_roles(\@roles);
+ # Replaces all of $actor's previous roles with the two named
-Replace all the related objects with the given 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 C<add_to_$rel> repeatedly to
-link all the new objects.
+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
+C<add_to_$rel> repeatedly to link all the new objects.
Note that this means that this method will B<not> delete any objects in the
table on the right side of the relation, merely that it will delete the link
between them.
+Due to a mistake in the original implementation of this method, it will also
+accept a list of objects or hash references. This is B<deprecated> and will be
+removed in a future version.
+
=head2 remove_from_$rel
B<Currently only available for C<many-to-many> relationships.>
@_ > 0 or $self->throw_exception(
"{$set_meth} needs a list of objects or hashrefs"
);
+ my @to_set = (ref($_[0] eq 'ARRAY') ? @{ $_[0] } : @_);
$self->search_related($rel, {})->delete;
- $self->$add_meth(shift) while (defined $_[0]);
+ $self->$add_meth(shift) for (@to_set);
};
*{"${class}::${remove_meth}"} = sub {