In my music database I have CD objects that belong to an Artist. I want the
artist primary key but I don't want to hit
the database (or do a join with a prefetch) just to get the id.
my $artist = $cd->artist; # hits the database again
my $artist_id = $artist->id;
I know I can use get_column() to get the column data, but I still want to
inflate other columns. So, normally I want to call the accessor on the
object.
So, basically, what I'm looking to do is a way to detect when to use
get_column() in a generic way:
my $item = $cd;
my @col = qw/ id title year artist /;
my %hash;
for my $accessor ( @col ) {
$hash{$accessor} = $item->is_belongs_to_relationship( $accessor )
? $item->get_column( $accessor ) # return raw foreign key value
: $item->$accessor;
}
What's an efficient way to detect the belongs_to relationship?
Thanks,
--
Bill Moseley
[email protected]
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]