fix find_related-based queries to correctly grep the unique key
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship / ManyToMany.pm
index 65eab45..e294a8c 100644 (file)
@@ -60,8 +60,9 @@ sub many_to_many {
       @_ > 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($_) for (@to_set);
     };
 
     *{"${class}::${remove_meth}"} = sub {