[Bast-commits] r3844 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class t
captainL at dev.catalyst.perl.org
captainL at dev.catalyst.perl.org
Mon Oct 29 20:26:03 GMT 2007
Author: captainL
Date: 2007-10-29 20:26:02 +0000 (Mon, 29 Oct 2007)
New Revision: 3844
Modified:
DBIx-Class/0.08/trunk/Changes
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/trunk/t/90join_torture.t
DBIx-Class/0.08/trunk/t/91merge_attr.t
Log:
fixed _merge_attr bug
Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes 2007-10-29 17:19:01 UTC (rev 3843)
+++ DBIx-Class/0.08/trunk/Changes 2007-10-29 20:26:02 UTC (rev 3844)
@@ -1,4 +1,5 @@
Revision history for DBIx::Class
+ - Fixed join merging bug (test from Zbi)
- When adding relationships, it will throw an exception if you get the
foreign and self parts the wrong way round in the condition
- ResultSetColumn::func() now returns all results if called in list
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2007-10-29 17:19:01 UTC (rev 3843)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2007-10-29 20:26:02 UTC (rev 3844)
@@ -2078,10 +2078,10 @@
$position++;
}
my ($b_key) = ( ref $b_element eq 'HASH' ) ? keys %{$b_element} : ($b_element);
+
if ($best_candidate->{score} == 0 || exists $seen_keys->{$b_key}) {
push( @{$a}, $b_element );
} else {
- $seen_keys->{$b_key} = 1; # don't merge the same key twice
my $a_best = $a->[$best_candidate->{position}];
# merge a_best and b_element together and replace original with merged
if (ref $a_best ne 'HASH') {
@@ -2091,6 +2091,7 @@
$a->[$best_candidate->{position}] = { $key => $self->_merge_attr($a_best->{$key}, $b_element->{$key}) };
}
}
+ $seen_keys->{$b_key} = 1; # don't merge the same key twice
}
return $a;
Modified: DBIx-Class/0.08/trunk/t/90join_torture.t
===================================================================
--- DBIx-Class/0.08/trunk/t/90join_torture.t 2007-10-29 17:19:01 UTC (rev 3843)
+++ DBIx-Class/0.08/trunk/t/90join_torture.t 2007-10-29 20:26:02 UTC (rev 3844)
@@ -6,7 +6,7 @@
use DBICTest;
my $schema = DBICTest->init_schema();
-plan tests => 20;
+plan tests => 22;
{
my $rs = $schema->resultset( 'CD' )->search(
@@ -119,4 +119,10 @@
ok(!$@, "pathological prefetch ok");
+my $rs = $schema->resultset("Artist")->search({}, { join => 'twokeys' });
+my $second_search_rs = $rs->search({ 'cds_2.cdid' => '2' }, { join =>
+['cds', 'cds'] });
+is(scalar(@{$second_search_rs->{attrs}->{join}}), 3, 'both joins kept');
+ok($second_search_rs->next, 'query on double joined rel runs okay');
+
1;
Modified: DBIx-Class/0.08/trunk/t/91merge_attr.t
===================================================================
--- DBIx-Class/0.08/trunk/t/91merge_attr.t 2007-10-29 17:19:01 UTC (rev 3843)
+++ DBIx-Class/0.08/trunk/t/91merge_attr.t 2007-10-29 20:26:02 UTC (rev 3844)
@@ -6,7 +6,7 @@
use DBICTest;
use Test::More;
-plan tests => 14;
+plan tests => 15;
my $schema = DBICTest->init_schema();
my $rs = $schema->resultset( 'CD' );
@@ -52,6 +52,14 @@
}
{
+ my $a = [ 'twokeys' ];
+ my $b = [ 'cds', 'cds' ];
+ my $expected = [ 'twokeys', 'cds', 'cds' ];
+ my $result = $rs->_merge_attr($a, $b);
+ is_deeply( $result, $expected );
+}
+
+{
my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
my $b = 'artist';
my $expected = [ 'artist', 'cd', { 'artist' => 'manager' } ];
More information about the Bast-commits
mailing list