my $schema = DBICTest->init_schema();
-plan tests => 11;
+plan tests => 14;
my $cd;
my $rs = $cd = $schema->resultset("CD")->search({});
my $rsc = $rs->get_column('year');
is( $rsc->{_parent_resultset}->{attrs}->{prefetch}, undef, 'prefetch wiped' );
}
+
+# test sum()
+is ($schema->resultset('BooksInLibrary')->get_column ('price')->sum, 125, 'Sum of a resultset works correctly');
+
+# test sum over search_related
+my $owner = $schema->resultset('Owners')->find ({ name => 'Newton' });
+ok ($owner->books->count > 1, 'Owner Newton has multiple books');
+is ($owner->search_related ('books')->get_column ('price')->sum, 60, 'Correctly calculated price of all owned books');
]);
$schema->populate('BooksInLibrary', [
- [ qw/id owner title source/ ],
- [ 1, 1, "Programming Perl", "Library" ],
- [ 2, 1, "Dynamical Systems", "Library" ],
- [ 3, 2, "Best Recipe Cookbook", "Library" ],
+ [ qw/id owner title source price/ ],
+ [ 1, 1, "Programming Perl", "Library", 23 ],
+ [ 2, 1, "Dynamical Systems", "Library", 37 ],
+ [ 3, 2, "Best Recipe Cookbook", "Library", 65 ],
]);
}
data_type => 'varchar',\r
size => '100',\r
},\r
+ 'price' => {\r
+ data_type => 'integer',\r
+ is_nullable => 1,\r
+ },\r
);\r
__PACKAGE__->set_primary_key('id');\r
\r
--
-- Created by SQL::Translator::Producer::SQLite
--- Created on Fri Oct 24 21:31:55 2008
+-- Created on Sun Nov 2 15:27:04 2008
--
BEGIN TRANSACTION;
id INTEGER PRIMARY KEY NOT NULL,
source varchar(100) NOT NULL,
owner integer NOT NULL,
- title varchar(100) NOT NULL
+ title varchar(100) NOT NULL,
+ price integer
);