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

[prev] [thread] [next] [Date index for 2005/10/25]

From: Steven Mackenzie
Subject: Re: [CDBI] Making Class::DBI objects from a search_ method result?
Date: 15:41 on 25 Oct 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
> $self.cdid.

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,
Steven

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

Re: [CDBI] Making Class::DBI objects from a search_ method result?
Steven Mackenzie 15:41 on 25 Oct 2005

Generated at 14:18 on 27 Oct 2005 by mariachi v0.52