[Dbix-class] Oracle Prefetch / Join
Jess Robinson
castaway at desert-island.me.uk
Fri May 4 20:43:58 GMT 2007
On Fri, 4 May 2007, SHAD0WRUNNER at gmx.de wrote:
> Hello again,
>
> I tried this example with Oracle:
>
> Tables CDS -> Tracks
>
> #1. Package:
> #############
>
> package Schema::CD;
>
> use base qw/DBIx::Class/;
>
> __PACKAGE__->load_components(qw/ PK::Auto Core /);
>
> __PACKAGE__->table('cds');
>
> __PACKAGE__->add_columns(
> id => {
> data_type => "varchar2",
> size => "64",
> prec => "0",
> scale => "0",
> is_nullable => "n",
> }
> );
>
>
> __PACKAGE__->set_primary_key(qw/ id / );
>
> __PACKAGE__->has_many('tracks' => 'Schema::Track', 'cd_id');
>
> 1;
>
> #2. Package:
> #############
>
> package Schema::Track;
>
> use base qw/DBIx::Class/;
>
> __PACKAGE__->load_components(qw/ PK::Auto Core /);
>
> __PACKAGE__->table('tracks');
>
> __PACKAGE__->add_columns(
> id => {
> data_type => "varchar2",
> size => "64",
> prec => "0",
> scale => "0",
> is_nullable => "n",
> },
> cd_id => {
> data_type => "varchar2",
> size => "64",
> }
> );
>
>
> __PACKAGE__->set_primary_key(qw/ id / );
>
> __PACKAGE__->belongs_to('cd' => 'Schema::CD', 'cd_id');
>
> 1;
>
>
> #test.pl
> #########
> ....
>
> $rs = $schema->resultset('CD')->search( { id => "test" },
> {prefetch => "tracks"}
> );
>
> $i=1;
> while($rs->next){
> print "$i ...\n";
> $i++;
> }
>
>
>
> If there is 1 recordset in table CDS and 2 related recordsets in
> TRACKS I would expect:
>
> 1 ...
>
> but i got:
>
> 1 ...
> 2 ...
> 3 ...
>
> Is this the expected behavior?
>
> The same effect I got with join.
>
No. Care to rurn on DBIC_TRACE and give us the sql you got?
Jess
More information about the Dbix-class
mailing list