From: Peter Rabbitson Date: Fri, 22 Apr 2011 20:31:28 +0000 (+0200) Subject: Fix custom-relationships on resultsources with multilevel monikers X-Git-Tag: v0.08191~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=93508f48904821b475a06d9d2652ff6e8dd0cb98;p=dbsrgits%2FDBIx-Class.git Fix custom-relationships on resultsources with multilevel monikers --- diff --git a/Changes b/Changes index 4b1567a..b99dc97 100644 --- a/Changes +++ b/Changes @@ -62,6 +62,8 @@ Revision history for DBIx::Class the "root" columns are in fact injected from the right rs side - Fix the join optimizer to correctly preserve the non-multi path to a multi relationship ( x -> might_have y -> has_many z ) + - Fix object-derived custom-relationship resultsets to resultsources + with multilevel monikers (e.g. $schema->source('Foo::Bar') ) * Misc - Rewire all warnings to a new Carp-like implementation internal diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index afb7dd4..8e37e1c 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -444,9 +444,9 @@ sub related_resultset { # root alias as 'me', instead of $rel (as opposed to invoking # $rs->search_related) - local $source->{_relationships}{me} = $source->{_relationships}{$rel}; # make the fake 'me' rel my $obj_table_alias = lc($source->source_name) . '__row'; + $obj_table_alias =~ s/\W+/_/g; $source->resultset->search( $self->ident_condition($obj_table_alias), diff --git a/t/relationship/custom.t b/t/relationship/custom.t index c136224..060bb38 100644 --- a/t/relationship/custom.t +++ b/t/relationship/custom.t @@ -86,6 +86,39 @@ is_same_sql_bind( ], ] ); + +# re-test with ::-containing moniker name +# (we don't have any currently, so fudge it with lots of local() ) +{ + local $schema->source('Artist')->{source_name} = 'Ar::Tist'; + local $artist2->{related_resultsets}; + + is_same_sql_bind( + $artist2->cds_90s->as_query, + '( + SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track + FROM artist ar_tist__row + JOIN cd me + ON ( me.artist = ar_tist__row.artistid AND ( me.year < ? AND me.year > ? ) ) + WHERE ( ar_tist__row.artistid = ? ) + )', + [ + [ + { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.year' } + => 2000 + ], + [ + { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.year' } + => 1989 + ], + [ { sqlt_datatype => 'integer', dbic_colname => 'ar_tist__row.artistid' } + => 22 + ], + ] + ); +} + + my @cds_90s = $cds_90s_rs->all; is(@cds_90s, 6, '6 90s cds found (1990 - 1995) even with non-optimized search'); map { ok($_->year < 2000 && $_->year > 1989) } @cds_90s;