Re: [CDBI] How can you query the has_many relationships from a CDBI object?

[prev] [thread] [next] [Date index for 2005/11/22]

From: William Ross
Subject: Re: [CDBI] How can you query the has_many relationships from a CDBI object?
Date: 22:22 on 22 Nov 2005
On 17 Nov 2005, at 19:44, Phillip Moore wrote:

> Greetings, list members...
>
> This should be a simple question.
>
> <snip>
> So the question is: how can I query the %has_many relationships?    
> So far, it looks like I need to keep track of these as class data,  
> and provide a class method to access them, but it just seems to me  
> that this information must be queryable somehow.

It is.

   $class->meta_info(has_many => $relname);

will return something like:

$VAR1 = bless( {
     'foreign_class' => 'Delivery::Group::Document',
     'name' => 'has_many',
     'args' => {
         'mapping' => [
             'usergroup'
         ],
         'foreign_key' => 'document',
         'order_by' => undef
     },
     'class' => 'Delivery::Document',
     'accessor' => 'usergroups'
}, 'Class::DBI::Relationship::HasMany'


and shortening it to:

   $class->meta_info('has_many');

will return a reference to a hash of several such HasMany objects  
keyed by accessor name.

Around the cdbi modules you'll see variations on this code:

   my $meta = $class->meta_info($reltype => $accessor);
   my ($f_class, $f_key, $args) = ($meta->foreign_class, $meta->args-> 
{foreign_key}, $meta->args);

which should give you all the ingredients you need.

best,

will



_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

Re: [CDBI] How can you query the has_many relationships from a CDBI object?
William Ross 22:22 on 22 Nov 2005

Generated at 08:22 on 28 Nov 2005 by mariachi v0.52