[Dbix-class] Help with join
Maurice Height
mauriceh at bigpond.net.au
Mon Apr 24 11:53:53 CEST 2006
I cannot get a join to work in DBIx-Class-0.06002 entirely due to the fact I
can't figure it out.
I have 2 tables:
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/);
__PACKAGE__->has_many('indexes' => 'DB_Schema::Index_Companies', 'code');
1;
package DB_Schema::Index_Companies;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('index_companies');
__PACKAGE__->add_columns(qw/id code index_name/);
__PACKAGE__->set_primary_key(qw/id/);
__PACKAGE__->belongs_to(code => 'DB_Schema::Company');
1;
I want to do the query:
select company.code, company.igroup
from company
join index_companies ON company.code = index_companies.code
where index_companies.index_name = 'ASX300'
My (incorrect) code is:
my $rs = $schema->resultset('Company')->search(
{ 'index_companies.index_name' => 'ASX300',
},
{ join => [qw/index_companies/],
}
);
Which gives error:
DBIx::Class::ResultSet::search(): No such relationship index_companies at
...
What am I doing wrong?
Maurice
More information about the Dbix-class
mailing list