[Dbix-class] Help with join

luke saunders luke.saunders at gmail.com
Mon Apr 24 12:02:41 CEST 2006


You have to use the relationship name rather than the table name. So in your
case it should be:

my $rs = $schema->resultset('Company')->search(
        { 'indexes.index_name' => 'ASX300',
        },
        { join     => [qw/indexes/],
        }
);


Cheers,
Luke.

On 4/24/06, Maurice Height <mauriceh at bigpond.net.au> wrote:
>
> 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
>
>
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060424/1b5e22a1/attachment.htm 


More information about the Dbix-class mailing list