Subject: | Bug in Class::DBI::Relationship::HasMany |
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.
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";