updated changes. fixed ResultSetColumn w/prefetch problem
[dbsrgits/DBIx-Class.git] / t / 88result_set_column.t
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
a47e1233 8my $schema = DBICTest->init_schema();
2bb7b40b 9
3f6cc7e4 10plan tests => 9;
2bb7b40b 11
58d387fe 12my $cd;
2bb7b40b 13my $rs = $cd = $schema->resultset("CD")->search({});
14
15my $rs_title = $rs->get_column('title');
16my $rs_year = $rs->get_column('year');
17
18is($rs_title->next, 'Spoonful of bees', "next okay");
19
20my @all = $rs_title->all;
21cmp_ok(scalar @all, '==', 5, "five titles returned");
22
23cmp_ok($rs_year->max, '==', 2001, "max okay for year");
24is($rs_title->min, 'Caterwaulin\' Blues', "min okay for title");
25
26cmp_ok($rs_year->sum, '==', 9996, "three artists returned");
27
ae515736 28my $psrs = $schema->resultset('CD')->search({},
29 {
30 '+select' => \'COUNT(*)',
31 '+as' => 'count'
32 }
33);
34ok(defined($psrs->get_column('count')), '+select/+as count');
35
36$psrs = $schema->resultset('CD')->search({},
37 {
38 '+select' => [ \'COUNT(*)', 'title' ],
39 '+as' => [ 'count', 'addedtitle' ]
40 }
41);
42ok(defined($psrs->get_column('count')), '+select/+as arrayref count');
43ok(defined($psrs->get_column('addedtitle')), '+select/+as title');
44
3f6cc7e4 45{
46 my $rs = $schema->resultset("CD")->search({}, { prefetch => 'artist' });
47 my $rsc = $rs->get_column('year');
48 is( $rsc->{_parent_resultset}->{attrs}->{prefetch}, undef, 'prefetch wiped' );
49}