1 # Test if prefetch and join in diamond relationship fetching the correct rows
9 my $schema = DBICTest->init_schema();
11 $schema->populate('Artwork', [
16 $schema->populate('Artwork_to_Artist', [
17 [ qw/artwork_cd_id artist_id/ ],
21 my $ars = $schema->resultset ('Artwork');
23 # The relationship diagram here is:
25 # $ars --> artwork_to_artist
31 # The current artwork belongs to a cd by artist1
32 # but the artwork itself is painted by artist2
34 # What we try is all possible permutations of join/prefetch
35 # combinations in both directions, while always expecting to
36 # arrive at the specific artist at the end of each path.
41 'no cd empty' => [ '' ],
42 'no cd undef' => [ undef ],
43 'no cd href' => [ {} ],
44 'no cd aoh' => [ [{}] ],
45 'no cd complex' => [ [ [ undef ] ] ],
47 'cd->artist1' => [{'cd' => 'artist'}]
51 'no a2a empty ' => [ '' ],
52 'no a2a undef' => [ undef ],
53 'no a2a href' => [ {} ],
54 'no a2a aoh' => [ [{}] ],
55 'no a2a complex' => [ [ '' ] ],
56 'a2a' => ['artwork_to_artist'],
57 'a2a->artist2' => [{'artwork_to_artist' => 'artist'}]
62 foreach my $cd_path (keys %$cd_paths) {
64 foreach my $a2a_path (keys %$a2a_paths) {
67 $tests{sprintf "join %s, %s", $cd_path, $a2a_path} = $ars->search({}, {
69 @{ $cd_paths->{$cd_path} },
70 @{ $a2a_paths->{$a2a_path} },
77 $tests{sprintf "prefetch %s, %s", $cd_path, $a2a_path} = $ars->search({}, {
81 @{ $cd_paths->{$cd_path} },
82 @{ $a2a_paths->{$a2a_path} },
87 $tests{sprintf "join %s, prefetch %s", $cd_path, $a2a_path} = $ars->search({}, {
89 @{ $cd_paths->{$cd_path} },
92 @{ $a2a_paths->{$a2a_path} },
97 $tests{sprintf "join %s, prefetch %s", $a2a_path, $cd_path} = $ars->search({}, {
99 @{ $a2a_paths->{$a2a_path} },
102 @{ $cd_paths->{$cd_path} },
109 foreach my $name (keys %tests) {
110 foreach my $artwork ($tests{$name}->all()) {
111 is($artwork->id, 1, $name . ', correct artwork');
112 is($artwork->cd->artist->artistid, 1, $name . ', correct artist_id over cd');
113 is($artwork->artwork_to_artist->first->artist->artistid, 2, $name . ', correct artist_id over A2A');