[CDBI] Making Class::DBI objects from a search_ method result?
steven.mackenzie at aptile.co.uk
Mon Oct 24 15:13:43 BST 2005
I would like to add a convenience method to once of my Class::DBI
objects, so that I can get a collection of related CDBI instance objects
via a JOIN, rather than by following has_many relations.
>From looking at the doc
I think something like this should be possible:
# add a sub to get all persons in the band that created a CD; assumes
# that the current CD was created by a band!
( persons =>
FROM CD cd
JOIN artist a on cd.artistid = a.artistid
JOIN artistgroup ag on a.artistid = ag.bandartistid
JOIN person p on ag.personartistid = p.artistid
WHERE cd = $self.cdid
# ... elsewhere ...
my @persons = $cd->search_persons();
The array @persons is now an array of hashes. I'd rather it was an
array of PERSON rows though. Is there a nice way to do that?
More information about the ClassDBI