[CDBI] Making Class::DBI objects from a search_ method result?

Perrin Harkins perrin at elem.com
Mon Oct 24 17:07:29 BST 2005


On Mon, 2005-10-24 at 16:41 +0100, Steven Mackenzie wrote:
> I saw some discussion of sth_to_objects a few days back, but I'm still
> not sure of the usage. Is that something I could use in this situation?

The search method actually does it for you.  No doubt the
Class::DBI::Sweet method works, but your approach with the set_sql is
fine, and should work with no problems.  The only issue I see with what
you wrote is that the query belongs in your Person class, not in your CD
class, and you need to put in a placeholder for the cdid, not
$self.cdid.

So you'd call it like this:
my @persons = Person->search_by_cd( $cd->id() );

That should give you a list of Person objects.

- Perrin





More information about the ClassDBI mailing list