added test for incorrect alias _2 in join collapsing
Justin Guenther [Thu, 6 Jul 2006 19:58:52 +0000 (19:58 +0000)]
t/76joins.t

index 6001598..2082047 100644 (file)
@@ -297,4 +297,21 @@ cmp_ok($queries, '==', 1, 'Only one query run');
 
 $tree_like = $schema->resultset('TreeLike')->find(1);
 $tree_like = $tree_like->search_related('children')->search_related('children')->search_related('children')->first;
-is($tree_like->name, 'quux', 'Tree search_related ok');
\ No newline at end of file
+is($tree_like->name, 'quux', 'Tree search_related ok');
+
+# test that collapsed joins don't get a _2 appended to the alias
+
+my $sql = '';
+$schema->storage->debugcb(sub { $sql = $_[1] });
+$schema->storage->debug(1);
+
+eval {
+  my $row = $schema->resultset('Artist')->search_related('cds', undef, {
+    join => 'tracks',
+    prefetch => 'tracks',
+  })->search_related('tracks')->first;
+};
+
+like( $sql, qr/^SELECT tracks.trackid/, "collapsed join didn't add _2 to alias" );
+
+$schema->storage->debug(0);