Skip Menu |
 

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 95658
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: bokutin [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.082801



Subject: Question about collapse attribute
Download (untitled) / with headers
text/plain 3.4k
Hello. I asked about the behavior of collapse attribute. I shows the test code first. # full version is here https://github.com/bokutin/p5-ex-schema use Modern::Perl; use Test::More; use Ex1::Schema; # CREATE TABLE room ( # id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, # name # ); # # CREATE TABLE desk ( # id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, # room_id INTEGER, # name # ); # CREATE INDEX idx_desk_room_id ON desk(room_id); my $schema = do { my $DB_FILE = "ex.sqlite"; system( "rm $DB_FILE && sqlite3 $DB_FILE < schema.sql" ) == 0 or die; Ex1::Schema->connect("dbi:SQLite:dbname=$DB_FILE"); }; { my $rs = $schema->resultset('Room'); $rs->create( { name => 'room1', desks => [ { name => 'desk1' }, { name => 'desk2' }, { name => 'desk3' }, ], }, ); is $rs->count, 1; } { my $rs = $schema->resultset('Room')->search( { 'desks.name' => [ qw(desk1 desk2) ], }, { join => 'desks', } ); is $rs->count, 2, "not collapsed if attrs has join"; is 0+($rs->all), 2, "fetch == count"; } { my $rs = $schema->resultset('Room')->search( { 'desks.name' => [ qw(desk1 desk2) ], }, { prefetch => 'desks', } ); is $rs->count, 1, "auto collapsed if attrs has prefetch"; is 0+($rs->all), 1, "fetch == count"; } { my $rs = $schema->resultset('Room')->search( { 'desks.name' => [ qw(desk1 desk2) ], }, { join => 'desks', distinct => 1, } ); is $rs->count, 1, "collapsed if attrs has join & distinct"; is 0+($rs->all), 1, "fetch == count"; } { my $rs = $schema->resultset('Room')->search( { 'desks.name' => [ qw(desk1 desk2) ], }, { join => 'desks', collapse => 1, } ); is $rs->count, 1, "collapsed if attrs has join & collapse"; is 0+($rs->all), 2, "fetch != count! why??"; } done_testing; The last test is part of the question. The case of a combination of collapse and join, collapse will be considered to count(), but collapse is not considered to all(). Looking at the code, I found the following. % git checkout v0.08270 % vim % git diff diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index ffade21..9d14685 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1407,7 +1407,7 @@ sub _construct_results { ) ? 1 : 0 ) unless defined $self->{_result_inflator}{is_hri}; - if (! $attrs->{_related_results_construction}) { + if (! $attrs->{_related_results_construction} and ! $attrs->{collapse}) { # construct a much simpler array->hash folder for the one-table cases right here if ($self->{_result_inflator}{is_hri}) { for my $r (@$rows) { With the above changes, collapse will be considered to all(). prove test also passes. Behavior of the collapse attribute is a bug? Or it is a specification? Cheers, Tomohiro Hosaka
Subject: Re: [rt.cpan.org #95658] Question about collapse attribute
Date: Thu, 15 May 2014 10:21:26 +0000
To: Tomohiro Hosaka via RT <bug-DBIx-Class [...] rt.cpan.org>
From: Peter Rabbitson <ribasushi [...] cpan.org>
Thanks for the report - this is a bug. Fix ETA is about a week from now. Cheers!
Download (untitled) / with headers
text/plain 751b
Thanks for the reply. Today, I found a version 0.082700_01. I tried as follows. % prove -I /Users/bokutin/code/reading/DBIx-Class-0.082700_01/lib -I lib -v t t/ex1.t .. ok 1 ok 2 - not collapsed if attrs has join ok 3 - fetch == count ok 4 - not collapsed if attrs has prefetch ok 5 - fetch == count ok 6 - collapsed if attrs has join & distinct ok 7 - fetch == count ok 8 - collapsed if attrs has join & collapse ok 9 - fetch != count! why?? 1..9 ok All tests successful. Files=1, Tests=9, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.23 cusr 0.02 csys = 0.28 CPU) Result: PASS I'm afraid a awesome job in terms 0.082700_01. For this ticket, it does not seem to have been fixed yet.
Subject: Re: [rt.cpan.org #95658] Question about collapse attribute
Date: Thu, 24 Jul 2014 07:41:13 +0000
To: Tomohiro Hosaka via RT <bug-DBIx-Class [...] rt.cpan.org>
From: Peter Rabbitson <ribasushi [...] cpan.org>
On Thu, Jul 24, 2014 at 01:19:47AM -0400, Tomohiro Hosaka via RT wrote: Show quoted text
> Queue: DBIx-Class > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=95658 > > > Thanks for the reply. > > Today, I found a version 0.082700_01. > I tried as follows. > > % prove -I /Users/bokutin/code/reading/DBIx-Class-0.082700_01/lib -I lib -v t > t/ex1.t .. > ok 1 > ok 2 - not collapsed if attrs has join > ok 3 - fetch == count > ok 4 - not collapsed if attrs has prefetch > ok 5 - fetch == count > ok 6 - collapsed if attrs has join & distinct > ok 7 - fetch == count > ok 8 - collapsed if attrs has join & collapse > ok 9 - fetch != count! why?? > 1..9 > ok > All tests successful. > Files=1, Tests=9, 0 wallclock secs ( 0.02 usr 0.01 sys + 0.23 cusr 0.02 csys = 0.28 CPU) > Result: PASS > > I'm afraid a awesome job in terms 0.082700_01. > For this ticket, it does not seem to have been fixed yet.
This is correct, I was going to do another pass on small fixes. Yours will be included in _02, coming up likely today. Sorry for the delay.
Download (untitled) / with headers
text/plain 293b
On Thu Jul 24 07:19:45 2014, bokutin wrote: Show quoted text
> Thanks for the reply. > > Today, I found a version 0.082700_01. > I tried as follows. >
This is finally landed in https://github.com/dbsrgits/dbix-class/commit/6aa939284, using a different approach to the one suggested. Thank you for reporting!
It was confirmed that by using the DBIx-Class-0.082700_03, this bug has been resolved. Thank you!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.