On Thu, 9 Oct 2008 13:15:13 +0200 BUCHMULLER Norbert <[EMAIL PROTECTED]>
wrote:

> Can you confirm if it's really a bug? (Or what was that I overlooked?)

As no-one objected that this is not a bug, I created a patch + test case
for it. See the attachment.

On one point I'm not certain: whether I should use _merge_attr() or do
the merge manually. (I mean that I wasn't able to go that deep into
_merge_attr() to be able to decide if it's kinda general-purpose
attribute merger or something specialized for 'join' and 'prefetch'.)

> I tried to create at least a test for that (see the attached diff). In
> fact there's another issue with 88result_set_column.t: for me it seems
> that $psrs->get_column() returns a DBIx::Class::ResultSetColumn object
> even if no column exists with that name, so all the '+select/+as' tests
> are kind of useless.. :-( I added a test for that bug, too ('+select/+as
> nonexistent_column'). Currently that other bug/feature masks the tests
> for my original problem.

I fixed those as well: I replaced the get_column() calls on the resultset
with get_column() calls on a row object (ie. changed
"$rs->get_column('...')" to "$rs->first->get_column('...')"). Now
t/88result_set_column.t passes for me on the 0.08 trunk (r4922).

Can you please review my patch?

norbi
Index: t/88result_set_column.t
===================================================================
--- t/88result_set_column.t	(revision 4922)
+++ t/88result_set_column.t	(working copy)
@@ -7,7 +7,7 @@
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 10; 
+plan tests => 13; 
 
 my $cd;
 my $rs = $cd = $schema->resultset("CD")->search({});
@@ -33,7 +33,10 @@
         '+as'       => 'count'
     }
 );
-ok(defined($psrs->get_column('count')), '+select/+as count');
+ok(defined($psrs->first->get_column('count')), '+select/+as count');
+my $nonexistent_column;
+eval { $nonexistent_column = $psrs->first->get_column('nonexistent_column'); };
+ok(!defined($nonexistent_column), '+select/+as nonexistent_column');
 
 $psrs = $schema->resultset('CD')->search({},
     {
@@ -41,9 +44,23 @@
         '+as'       => [ 'count', 'addedtitle' ]
     }
 );
-ok(defined($psrs->get_column('count')), '+select/+as arrayref count');
-ok(defined($psrs->get_column('addedtitle')), '+select/+as title');
+ok(defined($psrs->first->get_column('count')), '+select/+as arrayref count');
+ok(defined($psrs->first->get_column('addedtitle')), '+select/+as title');
 
+$psrs = $schema->resultset('CD')->search({},
+    {
+        '+select'   => \'COUNT(*)',
+        '+as'       => 'count'
+    }
+)->search({},
+    {
+        '+select'   => 'title',
+        '+as'       => 'addedtitle'
+    }
+);
+ok(defined($psrs->first->get_column('count')), '+select/+as chained count');
+ok(defined($psrs->first->get_column('addedtitle')), '+select/+as chained title');
+
 {
   my $rs = $schema->resultset("CD")->search({}, { prefetch => 'artist' });
   my $rsc = $rs->get_column('year');
Index: lib/DBIx/Class/ResultSet.pm
===================================================================
--- lib/DBIx/Class/ResultSet.pm	(revision 4922)
+++ 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]

Reply via email to