[CDBI] Re: coding a join

"Arshavir Grigorian" <[email protected]> Mon, 16 Apr 2007 17:28:34 -0700
Newsgroups gmane.comp.lang.perl.modules.class-dbi
Message-ID <[email protected]>
Thanks. It worked.

package Class::Contact;

__PACKAGE__->set_sql( latest_contact_dt => 'select max(cm.create_dt)

 from communication cm, contact cn

where cm.contact_id = cn.id

  and cn.id = ?');
The way I call this is

$contact->sql_latest_contact_dt($contact->id);

Is there a more elegant way to code this so that the class knows to
use the caller's id when running that sql?




On 4/14/07, Edward J. Sabol <sabol-2oVx0MVsMgiP/[email protected]> wrote:
> Arshavir Grigorian wrote:
> > I think I need set_sql() but since Class::DBI expects the set_sql()
> > query to return a primary key, I am not sure how to proceed.
>
> That's incorrect. Please re-read the documentation, specifically these two
> sections:
>
> http://search.cpan.org/~tmtm/Class-DBI/lib/Class/DBI.pm#Ima%3A%3ADBI_queries
> http://search.cpan.org/~tmtm/Class-DBI/lib/Class/DBI.pm#Single_Value_SELECTs
>
> Hope this helps,
> Ed
>