[CDBI] Making Class::DBI objects from a search_ method result?
steven.mackenzie at aptile.co.uk
Tue Oct 25 16:41:14 BST 2005
Perrin Harkins wrote:
> On Mon, 2005-10-24 at 16:41 +0100, Steven Mackenzie wrote:
> 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
That's an interesting point that I have only just re-noticed -- all the
search methods are class methods, and in-fact are constructors!
I've been using CDBI objects to expose an API to my client code, and
have added has_a and has_many relations so that the DB is navigated via
object instances. My client code doesn't know about CDBI classes, so
that's why I added the search method as an object/instance method.
As an instance method, I need to pass one less parameter in to the
search method -- that's got to be good.
> So you'd call it like this:
> my @persons = Person->search_by_cd( $cd->id() );
> That should give you a list of Person objects.
That's where my mistake was -- I had put my set_sql on the wrong class
in my code, and so was getting confused because I had the wrong objects
being returned, but it still "worked" as a hash.
I've put the set_sql in the right class now (eg Persons), and a
convenience method on the "searching" class (eg CD) so that I can make
the call from an instance.
Thanks for your help,
More information about the ClassDBI