9 my $schema = DBICTest->init_schema();
13 my $rs = $schema->resultset('CD')->search({},
15 '+select' => \ 'COUNT(*)',
19 lives_ok(sub { $rs->first->get_column('count') }, 'additional count rscolumn present');
20 dies_ok(sub { $rs->first->get_column('nonexistent_column') }, 'nonexistant column requests still throw exceptions');
22 $rs = $schema->resultset('CD')->search({},
24 '+select' => [ \ 'COUNT(*)', 'title' ],
25 '+as' => [ 'count', 'addedtitle' ]
28 lives_ok(sub { $rs->first->get_column('count') }, 'multiple +select/+as columns, 1st rscolumn present');
29 lives_ok(sub { $rs->first->get_column('addedtitle') }, 'multiple +select/+as columns, 2nd rscolumn present');
31 # Tests a regression in ResultSetColumn wrt +select
32 $rs = $schema->resultset('CD')->search(undef,
34 '+select' => [ \'COUNT(*) AS year_count' ],
35 order_by => 'year_count'
38 my @counts = $rs->get_column('cdid')->all;
39 ok(scalar(@counts), 'got rows from ->all using +select');
41 $rs = $schema->resultset('CD')->search({},
43 '+select' => [ \ 'COUNT(*)', 'title' ],
44 '+as' => [ 'count', 'addedtitle' ]
49 '+as' => 'addedtitle2'
52 lives_ok(sub { $rs->first->get_column('count') }, '+select/+as chained search 1st rscolumn present');
53 lives_ok(sub { $rs->first->get_column('addedtitle') }, '+select/+as chained search 1st rscolumn present');
54 lives_ok(sub { $rs->first->get_column('addedtitle2') }, '+select/+as chained search 3rd rscolumn present');
57 # test the from search attribute (gets between the FROM and WHERE keywords, allows arbitrary subselects)
58 # also shows that outer select attributes are ok (i.e. order_by)
60 # from doesn't seem to be useful without using a scalarref - there were no initial tests >:(
62 my $cds = $schema->resultset ('CD')->search ({}, { order_by => 'me.cdid'}); # make sure order is consistent
63 cmp_ok ($cds->count, '>', 2, 'Initially populated with more than 2 CDs');
65 my $table = $cds->result_source->name;
66 my $subsel = $cds->search ({}, {
67 columns => [qw/cdid title/],
68 from => \ "(SELECT cdid, title FROM $table LIMIT 2) me",
71 is ($subsel->count, 2, 'Subselect correctly limited the rs to 2 cds');
72 is ($subsel->next->title, $cds->next->title, 'First CD title match');
73 is ($subsel->next->title, $cds->next->title, 'Second CD title match');
75 is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"');