Skip to content

Commit

Permalink
Fix custom-relationships on resultsources with multilevel monikers
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Apr 22, 2011
1 parent a4812ca commit 93508f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/Class/Relationship/Base.pm
Expand Up @@ -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),
Expand Down
33 changes: 33 additions & 0 deletions t/relationship/custom.t
Expand Up @@ -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;
Expand Down

0 comments on commit 93508f4

Please sign in to comment.