Skip to content

Commit

Permalink
Merge 'mystery_join' into 'trunk'
Browse files Browse the repository at this point in the history
r6544@Thesaurus (orig r6543):  ribasushi | 2009-06-08 11:44:59 +0200
Attempt to figure out why do we repeat joins on complex search_related
r6586@Thesaurus (orig r6585):  ribasushi | 2009-06-10 11:22:05 +0200
Move the rs preservation test to a more suitable place
r6589@Thesaurus (orig r6588):  ribasushi | 2009-06-10 13:15:48 +0200
Finally commit trully failing test
r6590@Thesaurus (orig r6589):  ribasushi | 2009-06-10 13:33:14 +0200
Duh, this was a pretty simple bug
  • Loading branch information
ribasushi committed Jun 10, 2009
2 parents 9117ccf + 7025db7 commit 0400b6b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
15 changes: 9 additions & 6 deletions lib/DBIx/Class/ResultSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2430,12 +2430,15 @@ sub _resolve_from {
my $source = $self->result_source;
my $attrs = $self->{attrs};

my $from = $attrs->{from}
|| [ {
-result_source => $source,
-alias => $attrs->{alias},
$attrs->{alias} => $source->from,
} ];
my $from = [ @{
$attrs->{from}
||
[{
-result_source => $source,
-alias => $attrs->{alias},
$attrs->{alias} => $source->from,
}]
}];

my $seen = { %{$attrs->{seen_join} || {} } };

Expand Down
4 changes: 2 additions & 2 deletions t/lib/DBICTest/Schema/Artist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ __PACKAGE__->has_many(
);

__PACKAGE__->has_many(
artist_to_artwork => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
artwork_to_artist => 'DBICTest::Schema::Artwork_to_Artist' => 'artist_id'
);
__PACKAGE__->many_to_many('artworks', 'artist_to_artwork', 'artwork');
__PACKAGE__->many_to_many('artworks', 'artwork_to_artist', 'artwork');


sub sqlt_deploy_hook {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
use strict;
use warnings;
use warnings;

use Test::More;
use Test::Exception;

use lib qw(t/lib);
use DBIC::SqlMakerTest;
use DBIC::DebugObj;
use DBICTest;
use Data::Dumper;

my $schema = DBICTest->init_schema();

my $orig_debug = $schema->storage->debug;

use IO::File;

BEGIN {
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
: ( tests => 10 );
}
plan tests => 22;

# A search() with prefetch seems to pollute an already joined resultset
# in a way that offsets future joins (adapted from a test case by Debolaz)
Expand Down Expand Up @@ -61,3 +55,35 @@ BEGIN {
is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after another search with prefetch')
}, 'second prefetching search ok');
}

# Also test search_related, but now that we have as_query simply compare before and after
my $artist = $schema->resultset ('Artist')->first;
my %q;

$q{a2a}{rs} = $artist->search_related ('artwork_to_artist');
$q{a2a}{query} = $q{a2a}{rs}->as_query;

$q{artw}{rs} = $q{a2a}{rs}->search_related ('artwork',
{ },
{ join => ['cd', 'artwork_to_artist'] },
);
$q{artw}{query} = $q{artw}{rs}->as_query;

$q{cd}{rs} = $q{artw}{rs}->search_related ('cd', {}, { join => [ 'artist', 'tracks' ] } );
$q{cd}{query} = $q{cd}{rs}->as_query;

$q{artw_back}{rs} = $q{cd}{rs}->search_related ('artwork',
{}, { join => { artwork_to_artist => 'artist' } }
)->search_related ('artwork_to_artist', {}, { join => 'artist' });
$q{artw_back}{query} = $q{artw_back}{rs}->as_query;

for my $s (qw/a2a artw cd artw_back/) {
my $rs = $q{$s}{rs};

lives_ok ( sub { $rs->first }, "first() on $s does not throw an exception" );

lives_ok ( sub { $rs->count }, "count() on $s does not throw an exception" );

is_same_sql_bind ($rs->as_query, $q{$s}{query}, "$s resultset unmodified (as_query matches)" );
}

0 comments on commit 0400b6b

Please sign in to comment.