Rename incorrectly named internal method (has nothing to do with MySQL)
Peter Rabbitson [Sun, 5 Sep 2010 10:49:37 +0000 (12:49 +0200)]
Add an extra test (written due to a false-alarm)

lib/DBIx/Class/ResultSet.pm
lib/DBIx/Class/Storage/DBI/Replicated.pm
lib/DBIx/Class/Storage/DBIHacks.pm
t/search/related_has_many.t [new file with mode: 0644]

index 2fa0717..5a88d57 100644 (file)
@@ -2555,7 +2555,7 @@ sub related_resultset {
     # (the select/as attrs were deleted in the beginning), we need to flip all
     # left joins to inner, so we get the expected results
     # read the comment on top of the actual function to see what this does
-    $attrs->{from} = $rsrc->schema->storage->_straight_join_to_node ($attrs->{from}, $alias);
+    $attrs->{from} = $rsrc->schema->storage->_inner_join_to_node ($attrs->{from}, $alias);
 
 
     #XXX - temp fix for result_class bug. There likely is a more elegant fix -groditi
index 46ad462..0511253 100644 (file)
@@ -314,7 +314,6 @@ has 'write_handler' => (
     svp_begin
     svp_release
     relname_to_table_alias
-    _straight_join_to_node
     _dbh_last_insert_id
     _fix_bind_params
     _default_dbi_connect_attributes
@@ -392,6 +391,8 @@ my @unimplemented = qw(
   _use_typeless_placeholders
   _supports_typeless_placeholders
   _determine_supports_typeless_placeholders
+
+  _inner_join_to_node
 );
 
 for my $method (@unimplemented) {
index 581ee2f..c46b0e3 100644 (file)
@@ -421,7 +421,7 @@ sub _resolve_column_info {
 # the top of the stack, and if not - make sure the chain is inner-joined down
 # to the root.
 #
-sub _straight_join_to_node {
+sub _inner_join_to_node {
   my ($self, $from, $alias) = @_;
 
   # subqueries and other oddness are naturally not supported
diff --git a/t/search/related_has_many.t b/t/search/related_has_many.t
new file mode 100644 (file)
index 0000000..a359b4e
--- /dev/null
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+my $cd_rs = $schema->resultset('CD')->search ({ artist => { '!=', undef }});
+
+# create some CDs without tracks
+$cd_rs->create({ artist => 1, title => 'trackless_foo', year => 2010 });
+$cd_rs->create({ artist => 1, title => 'trackless_bar', year => 2010 });
+
+my $tr_count = $schema->resultset('Track')->count;
+
+my $tr_rs = $cd_rs->search_related('tracks');
+
+
+my @tracks;
+while ($tr_rs->next) {
+  push @tracks, $_;
+}
+
+is (scalar @tracks, $tr_count, 'Iteration is correct');
+is ($tr_rs->count, $tr_count, 'Count is correct');
+is (scalar ($tr_rs->all), $tr_count, 'All is correct');
+
+done_testing;