]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/CDBI.pm
applied Peter J Speltz model/asform fixes
[maypole.git] / lib / Maypole / Model / CDBI.pm
index a5c65f65166c417f1171ee051e97768713ee188e..4423b69b63e2b5b2fad74158312b1d86e87da65b 100644 (file)
@@ -371,17 +371,36 @@ sub related_class {
      }
  }
 
+=head2 related_meta
+
+  $class->related_meta($col);
+
+Given a column  associated with a relationship it will return the relatation
+ship type and the meta info for the relationship on the column.
+
+=cut
+
+sub related_meta {
+    my ($self,$r, $accssr) = @_;
+    $self->_croak("You forgot to put the place holder for 'r' or forgot the accssr parameter") unless $accssr;
+    my $class_meta = $self->meta_info;
+    if (my ($rel_type) = grep { defined $class_meta->{$_}->{$accssr} }
+        keys %$class_meta)
+    { return  $rel_type, $class_meta->{$rel_type}->{$accssr} };
+}
+
+
 =head2 isa_class
 
-Returns class of a column inherited by is_a, assumes something can be more than one thing (have * is_a rels)
+Returns class of a column inherited by is_a.
 
 =cut
 
+# Maybe put this in IsA?
 sub isa_class {
   my ($class, $col) = @_;
   $class->_croak( "Need a column for isa_class." ) unless $col;
   my $isaclass;
-  # class col is first found in is returned 
   my $isa = $class->meta_info("is_a") || {}; 
   foreach ( keys %$isa ) {
     $isaclass = $isa->{$_}->foreign_class; 
@@ -395,7 +414,8 @@ sub isa_class {
 Returns hash ref of classes for accessors.
 
 This is an attempt at a more efficient method than calling "related_class()"
-a bunch of times when you need it for many relations. 
+a bunch of times when you need it for many relations.
+It may be good to call at startup and store in a global config. 
 
 =cut