On Tue, 28 Oct 2008 14:00:01 +0100 Peter Rabbitson
<[EMAIL PROTECTED]> wrote:
> You are missing the point - this .t file does _not_ test search
> attributes. It tests ResultsetColumn functionality. We are discussing
> the merits of the issues you brought up on IRC.
OK, now I see. I simply did not even think that there's no test case for
these select() attributes for the retrieval case. (I started with "ack
'\+select' t/", and assumed that the only match is what I'm looking
for.:-)
> Still what you want (the retrieval part to work correctly) can be
> tested both on a ResultSetColumn _and_ on a regular object. For
> simplicity I am asking you to add this to a new test file, and keep the
> two issues separate.
OK.
> Also please show us the patch :)
See the attached file. I also copied all the tests for '+select'/'+as'
from t/88result_set_column.t, as those were missing as well, if I
understand what you wrote.
Let me know what else I should change. (Sorry, I don't use an IRC client
nowadays, so I cannot join the discussion there.)
norbi
Index: t/76retrieve.t
===================================================================
--- t/76retrieve.t (revision 0)
+++ t/76retrieve.t (revision 0)
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 6;
+
+my $rs = $schema->resultset('CD')->search({},
+ {
+ '+select' => \'COUNT(*)',
+ '+as' => 'count'
+ }
+);
+lives_ok(sub { $rs->first->get_column('count') }, '+select/+as count');
+dies_ok(sub { $rs->first->get_column('nonexistent_column') }, '+select/+as nonexistent_column');
+
+$rs = $schema->resultset('CD')->search({},
+ {
+ '+select' => [ \'COUNT(*)', 'title' ],
+ '+as' => [ 'count', 'addedtitle' ]
+ }
+);
+lives_ok(sub { $rs->first->get_column('count') }, '+select/+as arrayref count');
+lives_ok(sub { $rs->first->get_column('addedtitle') }, '+select/+as title');
+
+$rs = $schema->resultset('CD')->search({},
+ {
+ '+select' => \'COUNT(*)',
+ '+as' => 'count'
+ }
+)->search({},
+ {
+ '+select' => 'title',
+ '+as' => 'addedtitle'
+ }
+);
+lives_ok(sub { $rs->first->get_column('count') }, '+select/+as chained count');
+lives_ok(sub { $rs->first->get_column('addedtitle') }, '+select/+as chained title');
Index: lib/DBIx/Class/ResultSet.pm
===================================================================
--- lib/DBIx/Class/ResultSet.pm (revision 5015)
+++ lib/DBIx/Class/ResultSet.pm (working copy)
@@ -200,7 +200,7 @@
my $new_attrs = { %{$our_attrs}, %{$attrs} };
# merge new attrs into inherited
- foreach my $key (qw/join prefetch/) {
+ foreach my $key (qw/join prefetch +select +as/) {
next unless exists $attrs->{$key};
$new_attrs->{$key} = $self->_merge_attr($our_attrs->{$key}, $attrs->{$key});
}
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]