Relationship metadata

From ClassDBI

Jump to: navigation, search

I wish the CDBI object could report about its relationships and other special properties (has_a/has_many in particular) in addition to its columns.

Solution: You should be able to get all this from the meta_info() method, which is undocumented, but should be stable.

Unofficial Documentation for meta_info

This class method provides introspection facilities to subclasses of Class::DBI. It can be called with 0, 1, or 2 parameters. The 0 parameter form returns a hashref with meta information about the class. When this method is called with additional parameters, each subsequent parameter is like a hash lookup that goes one level deeper.

Example: 0 parameters

 use YAML;
 my $meta = My::Object->meta_info();
 print Dump($meta);

Example: 1 parameter

There are only two meaningful values that can be passed to the one parameter form: 'has_a' and 'has_many'.

 # $has_many eq $meta{has_many}
 my $has_many = My::Object->meta_info('has_many');

 foreach (keys %$has_many) {
   print "My::Object has many $_\n";
 }

Example: 2 parameters

The two parameter form goes one level deeper into the hashref.

 # $emails eq $meta{has_many}{emails}
 my $emails = My::Object->meta_info('has_many' => 'emails');

-- JohnBeppu, 2004-09-14

Personal tools