[CDBI] Re: coding a join

Michael Reece mreece at vinq.com
Tue Apr 17 17:12:12 BST 2007


i usually end up with something like

sub latest_contact_dt {
     my $self = shift;
     return $self->sql_latest_contact_dt->select_val($self->id);
}

On Apr 16, 2007, at 5:28 PM, Arshavir Grigorian wrote:

> 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 at alderaan.gsfc.nasa.gov> 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
>>
>
> _______________________________________________
> ClassDBI mailing list
> ClassDBI at lists.digitalcraftsmen.net
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

---
michael reece :: software engineer :: mreece at vinq.com





More information about the ClassDBI mailing list