Peter,
The original related_class method looked like an unfinished experiment to me,
and yes it is badly named because it confines itself to has_many's only.
If it's any help, here is a chunk from our application model class which I
coded earlier this year. I vaguely remember discovering that related_class as
it stood then was broken and also never used anywhere, so I fixed it and kept
on bravely not using it.
Right now I would have to invest serious time trying to re-learn both the
original code and my alleged fix, which involved quite a bit of Class::DBI
digging. So I can't make any useful comment right now about why I thought it
was broken and why my version was any better, but here it is..
###########################
# override this Maypole::Model::CDBI method which is broken there, but never
used.
sub related_class {
my ( $self, $accessor ) = @_;
my $meta_has_many = $self->meta_info('has_many') || return;
my $meta_accessor = $meta_has_many->{$accessor} || return;
my $mapping = $meta_accessor->{args}->{mapping} || [];
return
$meta_accessor->{foreign_class}->meta_info('has_a')->{$$mapping[0]}->{foreign_class}
if @$mapping;
return $meta_accessor->{foreign_class};
}
############################
>>> Peter Speltz <[EMAIL PROTECTED]> 10/09/05 4:07 PM >>>
Anyone else feel the related class sub in Maypole::Model::CDBI should
be general and return the related class no matter what relationship?
I guess so since the docs suggest it should.
I needed it to so i modified it. Here it is in the flesh and it has
worked so far.
sub related_class {
my ( $self, $r, $accessor ) = @_;
my $meta = $self->meta_info;
my @rels = keys %$meta;
my $related;
foreach (@rels) {
$related = $meta->{$_}{$accessor};
last if $related;
}
return unless $related;
my $mapping = $related->{args}->{mapping};
if ( $mapping and @$mapping ) { # bug was here : if (@$mapping) died
return $related->{foreign_class}->meta_info('has_a')->{ $$mapping[0] }
->{foreign_class};
}
else {
return $related->{foreign_class};
}
}
Cheers,
Peter
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Maypole-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-devel
This message (including any attachments) is intended solely for the addressee
named and may contain confidential and privileged information. If you are not
the intended recipient, please delete it and notify the sender.
Views expressed in this message are those of the individual sender, and are not
necessarily the views of the Independent Transport Safety and Reliability
Regulator (ITSRR). Whole or parts of this e-mail may be subject to copyright
of ITSRR or third parties. You should only re-transmit, distribute or use the
material for commercial purposes if you are authorised to do so.
Visit us at:
www.transportregulator.nsw.gov.au or Telephone: (02) 8263 7100
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Maypole-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-devel