1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
3 # Test if prefetch and join in diamond relationship fetching the correct rows
11 my $schema = DBICTest->init_schema();
13 $schema->populate('Artwork', [
18 $schema->populate('Artwork_to_Artist', [
19 [ qw/artwork_cd_id artist_id/ ],
23 my $ars = $schema->resultset ('Artwork');
25 # The relationship diagram here is:
27 # $ars --> artwork_to_artist
33 # The current artwork belongs to a cd by artist1
34 # but the artwork itself is painted by artist2
36 # What we try is all possible permutations of join/prefetch
37 # combinations in both directions, while always expecting to
38 # arrive at the specific artist at the end of each path.
43 'no cd empty' => [ '' ],
44 'no cd undef' => [ undef ],
45 'no cd href' => [ {} ],
46 'no cd aoh' => [ [{}] ],
47 'no cd complex' => [ [ [ undef ] ] ],
49 'cd->artist1' => [{'cd' => 'artist'}]
53 'no a2a empty ' => [ '' ],
54 'no a2a undef' => [ undef ],
55 'no a2a href' => [ {} ],
56 'no a2a aoh' => [ [{}] ],
57 'no a2a complex' => [ [ '' ] ],
58 'a2a' => ['artwork_to_artist'],
59 'a2a->artist2' => [{'artwork_to_artist' => 'artist'}]
64 foreach my $cd_path (keys %$cd_paths) {
66 foreach my $a2a_path (keys %$a2a_paths) {
69 $tests{sprintf "join %s, %s", $cd_path, $a2a_path} = $ars->search({}, {
71 @{ $cd_paths->{$cd_path} },
72 @{ $a2a_paths->{$a2a_path} },
79 $tests{sprintf "prefetch %s, %s", $cd_path, $a2a_path} = $ars->search({}, {
83 @{ $cd_paths->{$cd_path} },
84 @{ $a2a_paths->{$a2a_path} },
89 $tests{sprintf "join %s, prefetch %s", $cd_path, $a2a_path} = $ars->search({}, {
91 @{ $cd_paths->{$cd_path} },
94 @{ $a2a_paths->{$a2a_path} },
99 $tests{sprintf "join %s, prefetch %s", $a2a_path, $cd_path} = $ars->search({}, {
101 @{ $a2a_paths->{$a2a_path} },
104 @{ $cd_paths->{$cd_path} },
111 foreach my $name (keys %tests) {
112 foreach my $artwork ($tests{$name}->all()) {
113 is($artwork->id, 1, $name . ', correct artwork');
114 is($artwork->cd->artist->artistid, 1, $name . ', correct artist_id over cd');
115 is($artwork->artwork_to_artist->first->artist->artistid, 2, $name . ', correct artist_id over A2A');