12 my $schema = DBICTest->init_schema();
14 my $tkfks = $schema->resultset('FourKeys_to_TwoKeys');
16 warn "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
18 my ($fa, $fb) = $tkfks->related_resultset ('fourkeys')->populate ([
19 [qw/foo bar hello goodbye sensors read_count/],
24 # This is already provided by DBICTest
25 #my ($ta, $tb) = $tkfk->related_resultset ('twokeys')->populate ([
30 my ($ta, $tb) = $schema->resultset ('TwoKeys')
31 ->search ( [ { artist => 1, cd => 1 }, { artist => 2, cd => 2 } ])
34 my $tkfk_cnt = $tkfks->count;
36 my $non_void_ctx = $tkfks->populate ([
37 { autopilot => 'a', fourkeys => $fa, twokeys => $ta, pilot_sequence => 10 },
38 { autopilot => 'b', fourkeys => $fb, twokeys => $tb, pilot_sequence => 20 },
39 { autopilot => 'x', fourkeys => $fa, twokeys => $tb, pilot_sequence => 30 },
40 { autopilot => 'y', fourkeys => $fb, twokeys => $ta, pilot_sequence => 40 },
42 is ($tkfks->count, $tkfk_cnt += 4, 'FourKeys_to_TwoKeys populated succesfully');
45 # Make sure the forced group by works (i.e. the joining does not cause double-updates)
48 # create a resultset matching $fa and $fb only
49 my $fks = $schema->resultset ('FourKeys')
50 ->search ({ map { $_ => [1, 2] } qw/foo bar hello goodbye/}, { join => 'fourkeys_to_twokeys' });
52 is ($fks->count, 4, 'Joined FourKey count correct (2x2)');
53 $fks->update ({ read_count => \ 'read_count + 1' });
54 $_->discard_changes for ($fa, $fb);
56 is ($fa->read_count, 11, 'Update ran only once on joined resultset');
57 is ($fb->read_count, 21, 'Update ran only once on joined resultset');
61 # Make sure multicolumn in or the equivalen functions correctly
64 my $sub_rs = $tkfks->search (
66 { map { $_ => 1 } qw/artist.artistid cd.cdid fourkeys.foo fourkeys.bar fourkeys.hello fourkeys.goodbye/ },
67 { map { $_ => 2 } qw/artist.artistid cd.cdid fourkeys.foo fourkeys.bar fourkeys.hello fourkeys.goodbye/ },
70 join => [ 'fourkeys', { twokeys => [qw/artist cd/] } ],
74 is ($sub_rs->count, 2, 'Only two rows from fourkeys match');
76 # attempts to delete a grouped rs should fail miserably
78 sub { $sub_rs->search ({}, { distinct => 1 })->delete },
79 qr/attempted a delete operation on a resultset which does group_by/,
80 'Grouped rs update/delete not allowed',
83 # grouping on PKs only should pass
84 $sub_rs->search ({}, { group_by => [ reverse $sub_rs->result_source->primary_columns ] }) # reverse to make sure the comaprison works
85 ->update ({ pilot_sequence => \ 'pilot_sequence + 1' });
88 [ $tkfks->search ({ autopilot => [qw/a b x y/]}, { order_by => 'autopilot' })
89 ->get_column ('pilot_sequence')->all
92 'Only two rows incremented',
97 is ($tkfks->count, $tkfk_cnt -= 2, 'Only two rows deleted');