X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F88result_set_column.t;h=ff8db9e8bc717757bdc06bdb6edb3ef518a80266;hb=5b3090637dc0ea8949627267561820b43ff8e1cb;hp=847483af0b4ea6d7f0bcd879fd2398807b26d1a3;hpb=472d7df3682bdb73a76af18c6c78e4596cb8aa73;p=dbsrgits%2FDBIx-Class.git diff --git a/t/88result_set_column.t b/t/88result_set_column.t index 847483a..ff8db9e 100644 --- a/t/88result_set_column.t +++ b/t/88result_set_column.t @@ -47,8 +47,8 @@ warnings_exist (sub { # test distinct propagation is_deeply ( - [$rs->search ({}, { distinct => 1 })->get_column ('year')->all], - [$rs_year->func('distinct')], + [sort $rs->search ({}, { distinct => 1 })->get_column ('year')->all], + [sort $rs_year->func('distinct')], 'distinct => 1 is passed through properly', ); @@ -153,4 +153,43 @@ is_deeply ( 'prefetch properly collapses amount of rows from get_column', ); +$rs->reset; +my $pob_rs = $rs->search({}, { + select => ['me.title', 'tracks.title'], + prefetch => 'tracks', + order_by => [{-asc => ['position']}], + group_by => ['me.title', 'tracks.title'], +}); +is_same_sql_bind ( + $pob_rs->get_column("me.title")->as_query, + '(SELECT me.title FROM (SELECT me.title, tracks.title FROM cd me LEFT JOIN track tracks ON tracks.cd = me.cdid GROUP BY me.title, tracks.title ORDER BY position ASC) me)', + [], + 'Correct SQL for prefetch/order_by/group_by' +); + +# test aggregate on a function +{ + my $tr_rs = $schema->resultset("Track"); + $tr_rs->create({ cd => 2, title => 'dealbreaker' }); + + is( + $tr_rs->get_column('cd')->max, + 5, + "Correct: Max cd in Track is 5" + ); + + my $track_counts_per_cd_via_group_by = $tr_rs->search({}, { + columns => [ 'cd', { cnt => { count => 'trackid', -as => 'cnt' } } ], + group_by => 'cd', + })->get_column('cnt'); + + is ($track_counts_per_cd_via_group_by->max, 4, 'Correct max tracks per cd'); + is ($track_counts_per_cd_via_group_by->min, 3, 'Correct min tracks per cd'); + is ( + sprintf('%0.1f', $track_counts_per_cd_via_group_by->func('avg') ), + '3.2', + 'Correct avg tracks per cd' + ); +} + done_testing;