[Dbix-class] How to code an 'equi-join'

Maurice Height mauriceh at bigpond.net.au
Mon Feb 13 03:16:30 CET 2006


I want to do a simple 'equi-join' on 2 MySQL tables
but cannot figure out how to do it.

My tables are defined in DBIC as:

package DB_Schema::History;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('history');
__PACKAGE__->add_columns(qw/code day open high low close volume/);
__PACKAGE__->set_primary_key(qw/code day/);
1;

And

package DB_Schema::Company;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('company');
__PACKAGE__->add_columns(qw/code name igroup/);
__PACKAGE__->set_primary_key(qw/code/);
1;

The following code works OK in MySQL Query Browser:

SELECT h.code, c.name, (h.close-h.open) as diff
FROM   history h
JOIN   company c ON h.code = c.code
WHERE  h.code = 'ANZ' AND day = '2006-02-10'

How do I code this in DBIx::Class?
Am I missing a relationship statement somewhere?
These 2 tables are ONLY related by the column 'code'.

Thanks
Maurice








More information about the Dbix-class mailing list