X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frelationship%2Fcustom.t;h=058636bdce3901a9d052a506f0c14f52143eb2d8;hb=5294fdc61249a48e2e330796f82e0f2035d0faaa;hp=564142b96309441909c7b1187c5b3c19eadb7b7e;hpb=576ae54b66e0c8e83be42713de0cc22bfbc731cf;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/relationship/custom.t b/t/relationship/custom.t index 564142b..058636b 100644 --- a/t/relationship/custom.t +++ b/t/relationship/custom.t @@ -217,8 +217,9 @@ is_deeply ( 'last_track via insane subquery condition works, even without prefetch', ); + my $artwork = $schema->resultset('Artwork')->search({},{ order_by => 'cd_id' })->first; -my @artists = $artwork->artists->all; +my @artists = $artwork->artists->search({}, { order_by => 'artistid' } ); is(scalar @artists, 2, 'the two artists are associated'); my @artwork_artists = $artwork->artwork_to_artist->all; @@ -232,23 +233,95 @@ foreach (@artwork_artists) { } 'belongs_to works with custom rels'; } -@artists = (); -lives_ok { - @artists = $artwork->artists_via_customcond->all; -} 'manytomany with extended rels in the has many works'; -is(scalar @artists, 2, 'two artists'); +is( + $schema->resultset('Artwork') + ->related_resultset( 'artwork_to_artist_via_opaque_customcond' ) + ->related_resultset( 'artist' ) + ->search({}, { collapse => 1 }) + ->count, + 2, + 'Custom rel works correctly', +); -@artists = (); -lives_ok { - @artists = $artwork->artist_limited_rank->all; -} 'can fetch many to many with optimized version'; -is(scalar @artists, 1, 'only one artist is associated'); +is ( + scalar $artwork->all_artists_via_opaque_customcond->all, + 2, + 'Expected two m2m associated artist objects via opaque costom cond' +); -@artists = (); -lives_ok { - @artists = $artwork->artist_limited_rank_opaque->all; -} 'can fetch many to many with non-optimized version'; -is(scalar @artists, 1, 'only one artist is associated'); +for (qw( artist_limited_rank artist_limited_rank_opaque )) { + is( + $schema->resultset('Artwork') + ->related_resultset( 'artwork_to_artist_via_opaque_customcond' ) + ->related_resultset( $_ ) + ->search({}, { collapse => 1 }) + ->count, + 1, + 'Condition over double custom rel works correctly', + ); + + is ( + scalar $artwork->$_->all, + 1, + 'Expected one m2m associated artist object via opaque custom cond + conditional far cond' + ); + + cmp_ok( + $artwork->${\"remove_from_$_"} ( $artists[1] ), + '==', + 0, + 'deletion action reports 0' + ); + + is ( + scalar $artwork->all_artists_via_opaque_customcond->all, + 2, + 'Indeed nothing was removed' + ); + + cmp_ok( + $artwork->${\"remove_from_$_"} ( $artists[0] ), + '==', + 1, + 'Removal reports correct count' + ); + + is ( + scalar $artwork->all_artists_via_opaque_customcond->all, + 1, + 'Indeed removed the matching artist' + ); + + $artwork->${\"set_$_"}([]); + + is ( + scalar $artwork->all_artists_via_opaque_customcond->all, + 0, + 'Everything removed via limited far cond' + ); + + # can't use the opaque one - need set_from_related to work + $artwork->set_artist_limited_rank( @artists ); + + { + local $TODO = 'Taking into account the relationship bridge condition is not likely to ever work... unless we get DQ hooked somehow'; + + is ( + scalar $artwork->all_artists_via_opaque_customcond->all, + 1, + 'Re-Addition passed through only one of the artists' + ); + } + + throws_ok { $artwork->set_all_artists_via_opaque_customcond( \@artists ) } + qr/\QRelationship 'artwork_to_artist_via_opaque_customcond' on source 'Artwork' does not resolve to a join-free condition fragment/; + + is ( + scalar $artwork->all_artists_via_opaque_customcond->all, + 2, + 'Everything still there as expected' + ); +} # Make a single for each last_track