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

Report information
The Basics
Id:
16493
Status:
open
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
d.rowles [...] outcometechnologies.com
Cc:
AdminCc:

BugTracker
Severity:
Wishlist
Broken in:
v3.0.9
Fixed in:
(no value)



MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Subject: Bug in Class::DBI::Relationship::HasMany
Content-Type: multipart/mixed; boundary="----------=_1134598856-17831-1"
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 711
Hi there, I reference my post to the Class::DBI mailing list, with MessageId <43A0775C.1000904@outcometechnologies.com>. Since upgrading from Class::DBI 0.96 to 3.0.12, I have noticed that when requesting a list/iterator of objects via a "has_many" relationship (for example, my @actors = $film->actors()), passing in an "order_by" argument no longer works. Specifically, calling "my @actors = $film->actors()" will work fine, however calling "my @actors = $film->actors({order_by => 'name'})" will not work, and dies with an error along the lines of "order_by is not a column of Actor". I attach a patch for "t/09-has_many.t", which amends this test to demonstrate the bug. Problem exists on perl 5.8.3.
Content-Type: text/plain; name="bug.diff"
Content-Disposition: inline; filename="bug.diff"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 979
diff -ur Class-DBI-v3.0.12.old/t/09-has_many.t Class-DBI-v3.0.12.new/t/09-has_many.t --- Class-DBI-v3.0.12.old/t/09-has_many.t 2005-10-23 15:06:37.000000000 +0100 +++ Class-DBI-v3.0.12.new/t/09-has_many.t 2005-12-14 22:14:19.000000000 +0000 @@ -3,7 +3,7 @@ BEGIN { eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 42); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 45); } use lib 't/testlib'; @@ -79,6 +79,18 @@ is $actors[1]->Name, $pvj->Name, "PVJ first"; } + +# Test that "order_by" can be passed into the actors() method too +# +{ + my @actors = $btaste->actors({order_by => "name DESC"}); + is @actors, 2, " - so now we have 2"; + is $actors[0]->Name, $pvj->Name, "PVJ first due to ordering"; + is $actors[1]->Name, $pj->Name, "PJ second due to ordering"; +} + + + eval { my @actors = $btaste->actors({Name => $pj->Name}); is @actors, 1, "One actor from restricted (sorted) has_many";
Return-Path: <tony@tmtm.com>
X-Original-To: bug-Class-DBI@rt.cpan.org
Delivered-To: cpan-bug+class-dbi@diesel.bestpractical.com
Received: from la.mx.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id 75A024D80CE for <bug-Class-DBI@rt.cpan.org>; Wed, 14 Dec 2005 17:58:50 -0500 (EST)
Received: (qmail 31981 invoked by alias); 14 Dec 2005 22:58:26 -0000
X-Spam-Check-BY: la.mx.develooper.com
Received-SPF: pass (x1.develooper.com: local policy)
Received: from soto.kasei.com (HELO soto.kasei.com) (80.76.206.154) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Wed, 14 Dec 2005 14:58:18 -0800
Received: by soto.kasei.com (Postfix, from userid 1011) id 41CF21D0FA; Wed, 14 Dec 2005 22:58:13 +0000 (GMT)
Date: Wed, 14 Dec 2005 22:58:13 +0000
From: Tony Bowden <tony@tmtm.com>
To: Guest via RT <bug-Class-DBI@rt.cpan.org>
Subject: Re: [cpan #16493] Bug in Class::DBI::Relationship::HasMany
Message-ID: <20051214225813.GA10326@soto.kasei.com>
References: <rt-16493@cpan> <rt-16493-49340.17.4739904740922@cpan.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <rt-16493-49340.17.4739904740922@cpan.org>
User-Agent: Mutt/1.5.5.1+cvs20040105i
RT-Send-Cc:
X-RT-Original-Encoding: us-ascii
Content-Length: 932
On Wed, Dec 14, 2005 at 05:20:57PM -0500, Guest via RT wrote:
Show quoted text
> I reference my post to the Class::DBI mailing list, with MessageId <43A0775C.1000904@outcometechnologies.com>.
I'm not on the mailing list, so a messageid isn't much use to me. If the message is important, then a URL to the archive would be useful.
Show quoted text
> Since upgrading from Class::DBI 0.96 to 3.0.12, I have noticed that > when requesting a list/iterator of objects via a "has_many" relationship > (for example, my @actors = $film->actors()), passing in an "order_by" > argument no longer works.
If this worked previously, then I believe it to have been an accident. It certainly isn't documented to work. Currently this only works as a compile-time option, not a run-time one: Film->has_many(actors => Actor, { order_by => 'name' }); I'll certainly look at patches to add the functionality you describe, but at the minute it's not meant to work. Thanks, Tony
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
X-RT-Original-Encoding: iso-8859-1
Content-Length: 659
[d.rowles@outcometechnologies.com - Wed Dec 14 19:46:42 2005]:
Show quoted text
> I enclose a patch that restores the ability to specify "order_by" > when retrieving data via a has_many relationship. The patch also > includes the additional test cases that I sent you with the original > bug report. > Please let me know if the patch is OK, or if you would like me to > make any other changes.
Thanks for this. To be honest, I'm having a little difficulty following the logic of the patch. It seems like quite a complex set of checks you're adding. If you can talk me through your thinking here I suspect there's probably something much simpler we could do. Thanks, Tony
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Message-Id: <rt-3.5.HEAD-26267-1138380916-1829.16493-0-0@rt.cpan.org>
Content-Type: text/plain; charset="utf8"
Content-Transfer-Encoding: binary
From: stennie@cpan.org
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 1483
Hrm .. order_by option for has_many relationships may not have been a documented feature, but it seems a sensible parallel to the option in search(), and has also been inadvertently used by other CPAN authors (eg. RT#17317). This definitely worked in previous releases, and the behaviour change looks to have been introduced in Class::DBI 3.0.11 which now converts the order_by hash into an array: http://search.cpan.org/diff?from=Class-DBI-v3.0.10&to=Class-DBI-v3.0.11#lib/Class/DBI/ Relationship/HasMany.pm Also note that the order_by options are only munged if this is the first parameter to a has_many search .. so you can still get away with something like: my @actors = $film->actors(name => 'Bob', {order_by => 'name'}) A simple patch to support order_by follows. Cheers, Stephen --- Class-DBI-v3.0.14/lib/Class/DBI/Relationship/HasMany.pm.dist 2005-10-24 00:06:37.000000000 +1000 +++ Class-DBI-v3.0.14/lib/Class/DBI/Relationship/HasMany.pm 2006-01-28 03:38:02.000000000 +1100 @@ -131,7 +131,7 @@ my ($class, $accessor) = ($rel->class, $rel->accessor); return sub { my ($self, @search_args) = @_; - @search_args = %{ $search_args[0] } if ref $search_args[0] eq "HASH"; + @search_args = %{ $search_args[0] } if (ref $search_args[0] eq "HASH" && !grep(/ ^order_by$/, keys %{$search_args[0]})); my $meta = $class->meta_info($rel->name => $accessor); my ($f_class, $f_key, $args) = ($meta->foreign_class, $meta->args->{foreign_key}, $meta->args);
X-Scanned-BY: AMaViS-ng at bestpractical
MIME-Version: 1.0
X-Spam-Status: No, hits=-2.6 required=8.0 tests=BAYES_00
In-Reply-To: <rt-3.5.HEAD-26267-1138380916-1829.16493-5-0@rt.cpan.org>
Content-Disposition: inline
Received-SPF: pass (x1.develooper.com: local policy)
References: <RT-Ticket-16493@rt.cpan.org> <rt-3.5.HEAD-26267-1138380916-1829.16493-5-0@rt.cpan.org>
Reply-To: tony@kasei.com
Content-Type: text/plain; charset="utf-8"
X-RT-Original-Encoding: us-ascii
Received: from localhost (localhost.localdomain [127.0.0.1]) by diesel.bestpractical.com (Postfix) with ESMTP id AD9144D838C for <cpan-bug+class-dbi@diesel.bestpractical.com>; Fri, 27 Jan 2006 12:15:41 -0500 (EST)
Received: from la.mx.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id 61B434D838B for <bug-Class-DBI@rt.cpan.org>; Fri, 27 Jan 2006 12:15:41 -0500 (EST)
Received: (qmail 10162 invoked by alias); 27 Jan 2006 17:15:09 -0000
Received: from soto.kasei.com (HELO soto.kasei.com) (80.76.206.154) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Fri, 27 Jan 2006 09:15:02 -0800
Received: by soto.kasei.com (Postfix, from userid 1011) id CC2341C3FE; Fri, 27 Jan 2006 17:14:57 +0000 (GMT)
Delivered-To: cpan-bug+class-dbi@diesel.bestpractical.com
Subject: Re: [rt.cpan.org #16493] Request for order_by in has_many
User-Agent: Mutt/1.5.5.1+cvs20040105i
Return-Path: <tony@kasei.com>
X-Spam-Check-BY: la.mx.develooper.com
X-Original-To: cpan-bug+class-dbi@diesel.bestpractical.com
Date: Fri, 27 Jan 2006 17:14:57 +0000
Message-Id: <20060127171457.GA26394@soto.kasei.com>
To: Guest via RT <bug-Class-DBI@rt.cpan.org>
From: Tony Bowden <tony@kasei.com>
X-RT-Original-Encoding: utf-8
RT-Message-ID: <rt-3.5.HEAD-26255-1138382147-1017.16493-0-0@rt.cpan.org>
Content-Length: 300
On Fri, Jan 27, 2006 at 11:55:19AM -0500, Guest via RT wrote:
Show quoted text
> A simple patch to support order_by follows.
I'm open to something like this, but I don't really like the grepping on an explicit regex like this. A failing test case would be useful as well, if there isn't one already. Thanks, Tony
X-Scanned-BY: Outcome Technologies
X-Scanned-BY: AMaViS-ng at bestpractical
X-Originalarrivaltime: 31 Jan 2006 20:07:12.0238 (UTC) FILETIME=[EC4828E0:01C626A1]
MIME-Version: 1.0 (Apple Message framework v746.2)
X-Spam-Status: No, hits=-2.6 required=8.0 tests=BAYES_00,SPF_PASS
In-Reply-To: <rt-3.5.HEAD-26255-1138382147-1017.16493-6-0@rt.cpan.org>
X-Mailer: Apple Mail (2.746.2)
Received-SPF: pass (x1.develooper.com: domain of D.Rowles@outcometechnologies.com designates 212.135.97.6 as permitted sender)
References: <RT-Ticket-16493@rt.cpan.org> <rt-3.5.HEAD-26267-1138380916-1829.16493-5-0@rt.cpan.org> <20060127171457.GA26394@soto.kasei.com> <rt-3.5.HEAD-26255-1138382147-1017.16493-6-0@rt.cpan.org>
Content-Type: text/plain; charset="utf-8"; delsp="yes"; format="flowed"
X-Spam-Rules:
X-RT-Original-Encoding: US-ASCII
X-Spam-Score: (0)
Received: from localhost (localhost.localdomain [127.0.0.1]) by diesel.bestpractical.com (Postfix) with ESMTP id 3DEDB4D8280 for <cpan-bug+class-dbi@diesel.bestpractical.com>; Tue, 31 Jan 2006 15:08:20 -0500 (EST)
Received: from la.mx.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id D73B34D827F for <bug-Class-DBI@rt.cpan.org>; Tue, 31 Jan 2006 15:08:19 -0500 (EST)
Received: (qmail 21236 invoked by alias); 31 Jan 2006 20:07:46 -0000
Received: from emma.weboutcome.com (HELO emma.weboutcome.com) (212.135.97.6) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Tue, 31 Jan 2006 12:07:35 -0800
Received: from vicky.internal.weboutcome.com (vicky.internal.weboutcome.com [172.26.2.28]) by emma.weboutcome.com (8.12.3/8.12.3) with ESMTP id k0VK7Den015287 for <bug-Class-DBI@rt.cpan.org>; Tue, 31 Jan 2006 20:07:13 GMT
Received: from [192.168.20.121] ([192.168.0.43]) by vicky.internal.weboutcome.com with Microsoft SMTPSVC(5.0.2195.6713); Tue, 31 Jan 2006 20:07:12 +0000
Delivered-To: cpan-bug+class-dbi@diesel.bestpractical.com
Subject: Re: [rt.cpan.org #16493] Request for order_by in has_many
Return-Path: <D.Rowles@outcometechnologies.com>
X-Spam-Check-BY: la.mx.develooper.com
X-Original-To: cpan-bug+class-dbi@diesel.bestpractical.com
Date: Tue, 31 Jan 2006 20:07:11 +0000
Message-Id: <F17EFF6C-7323-451F-A036-4850AAC13E0F@outcometechnologies.com>
To: bug-Class-DBI@rt.cpan.org
Content-Transfer-Encoding: 7bit
From: Dan Rowles <d.rowles@outcometechnologies.com>
X-RT-Original-Encoding: utf-8
RT-Message-ID: <rt-3.5.HEAD-28588-1138738103-917.16493-0-0@rt.cpan.org>
Content-Length: 452
I think I did include a failing test case in the patch. Thanks, Dan On 27 Jan 2006, at 17:15, Tony Bowden via RT wrote:
Show quoted text
> On Fri, Jan 27, 2006 at 11:55:19AM -0500, Guest via RT wrote:
>> A simple patch to support order_by follows.
> > I'm open to something like this, but I don't really like the > grepping on > an explicit regex like this. > > A failing test case would be useful as well, if there isn't one > already. > > Thanks, > > Tony >


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

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