From: Peter Rabbitson Date: Mon, 21 Sep 2009 14:26:07 +0000 (+0000) Subject: A test for an obscure join syntax - make sure we don't break it X-Git-Tag: v0.08113~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=af439a0e0b2625bf72bbb6a3db651fdbffbe628f;p=dbsrgits%2FDBIx-Class.git A test for an obscure join syntax - make sure we don't break it --- diff --git a/t/relationship/core.t b/t/relationship/core.t index 566e5f3..6a09c57 100644 --- a/t/relationship/core.t +++ b/t/relationship/core.t @@ -5,12 +5,11 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use DBICTest; +use DBIC::SqlMakerTest; my $schema = DBICTest->init_schema(); my $sdebug = $schema->storage->debug; -plan tests => 79; - # has_a test my $cd = $schema->resultset("CD")->find(4); my ($artist) = ($INC{'DBICTest/HelperRels'} @@ -260,8 +259,22 @@ is($def_artist_cd->has_column_loaded('artist'), 1, 'FK loaded'); is($def_artist_cd->search_related('artist')->count, 0, 'closed search on null FK'); # test undirected many-to-many relationship (e.g. "related artists") -my $undir_maps = $schema->resultset("Artist")->find(1)->artist_undirected_maps; +my $undir_maps = $schema->resultset("Artist") + ->search ({artistid => 1}) + ->search_related ('artist_undirected_maps'); is($undir_maps->count, 1, 'found 1 undirected map for artist 1'); +is_same_sql_bind ( + $undir_maps->as_query, + '( + SELECT artist_undirected_maps.id1, artist_undirected_maps.id2 + FROM artist me + LEFT JOIN artist_undirected_map artist_undirected_maps + ON artist_undirected_maps.id1 = me.artistid OR artist_undirected_maps.id2 = me.artistid + WHERE ( artistid = ? ) + )', + [[artistid => 1]], + 'expected join sql produced', +); $undir_maps = $schema->resultset("Artist")->find(2)->artist_undirected_maps; is($undir_maps->count, 1, 'found 1 undirected map for artist 2'); @@ -310,3 +323,5 @@ is($cds->count, 1, "subjoins under left joins force_left (arrayref)"); $cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => { cd => {} } } }); is($cds->count, 1, "subjoins under left joins force_left (hashref)"); + +done_testing;