*grumble*inheritable classdata *grumble*
[catagits/Reaction.git] / lib / DBIx / Class / IntrospectableM2M.pm
index 7e8146c..e3a921e 100644 (file)
@@ -10,10 +10,13 @@ __PACKAGE__->mk_classdata( _m2m_metadata => {} );
 sub many_to_many {
   my $class = shift;
   my ($meth_name, $link, $far_side) = @_;
+  my $store = $class->_m2m_metadata;
+  die("You are overwritting another relationship's metadata")
+    if exists $store->{$meth_name};
 
-  $class->_m2m_metadata->{$meth_name} =
+  my $attrs =
     {
-     accessor => $meth_name, 
+     accessor => $meth_name,
      relation => $link, #"link" table or imediate relation
      foreign_relation => $far_side, #'far' table or foreign relation
      (@_ > 3 ? (attrs => $_[3]) : ()), #only store if exist
@@ -23,6 +26,9 @@ sub many_to_many {
      remove_method => "remove_from_${meth_name}",
     };
 
+  #inheritable data workaround/
+  $class->_m2m_metadata({ $meth_name => $attrs, %$store});
+
   $class->next::method(@_);
 }