converted the vendor tests to use schema objects intead of schema classes
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship / ManyToMany.pm
index 09cd751..d8d50de 100644 (file)
@@ -6,6 +6,15 @@ use warnings;
 
 sub many_to_many {
   my ($class, $meth, $rel, $f_rel, $rel_attrs) = @_;
+
+  $class->throw_exception(
+    "missing relation in many-to-many"
+  ) unless $rel;
+
+  $class->throw_exception(
+    "missing foreign relation in many-to-many"
+  ) unless $f_rel;
+
   {
     no strict 'refs';
     no warnings 'redefine';
@@ -60,9 +69,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] } : @_);
+      my @to_set = (ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_);
       $self->search_related($rel, {})->delete;
-      $self->$add_meth(shift) for (@to_set);
+      $self->$add_meth($_) for (@to_set);
     };
 
     *{"${class}::${remove_meth}"} = sub {