Re: [CDBI] Determining column relationship using __hasa_rels

[prev] [thread] [next] [Date index for 2005/10/17]

From: Peter Speltz
Subject: Re: [CDBI] Determining column relationship using __hasa_rels
Date: 14:55 on 17 Oct 2005
On 10/17/05, David Baird <lists.riverside@xxxxx.xxx> wrote:
> On 10/17/05, Kevin White <kevin@xxxxxxxxxxx.xx.xx> wrote:
> > Hi Folks,
> >
> > I am looking at Class::DBI::AsForm with a view to borrowing some bits
> > for a form builder suited to my own purposes and am having difficulty
> > with columns with relationships. The main problem is actually
> > identifying them. Is there anything I can use to check that a column
> > has a relationship on it? __hasa_rels is marked as deprecated in
> > Class::DBI and is returning undef.
> >
> > Thanks for any help
>
> Look at the meta_info() method instead.
>

Here is a method i put in my base CDBI class. It simply cycles thru
meta_info until it finds an accessor with its name.  It is from
Maypole::Model::CDBI with modification of mine.


###########
# related_class  #
###########

# Returns the class related to the accessor by a CDBI relationship.

sub related_class {
    my ( $self, $accessor ) =3D @_;
    my $meta =3D $self->meta_info;
    my @rels =3D keys %$meta;
    my $related;
    foreach (@rels) {
        $related =3D $meta->{$_}{$accessor};
        last if $related;
    }
    return unless $related;

    my $mapping =3D $related->{args}->{mapping};
    if ( $mapping and @$mapping ) {
        return $related->{foreign_class}->meta_info('has_a')->{
$$mapping[0] }->{foreign_class};
    }
    else {
        return $related->{foreign_class};
    }
}



pjs

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

Re: [CDBI] Determining column relationship using __hasa_rels
Peter Speltz 14:55 on 17 Oct 2005

Generated at 19:52 on 24 Oct 2005 by mariachi v0.52