From: Matt S Trout Date: Fri, 30 May 2008 14:36:16 +0000 (+0000) Subject: throw exception for multi-has_many prefetch X-Git-Tag: v0.08240~440 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cb136e67f71c272de046dfab5cec183f78cb5e08;p=dbsrgits%2FDBIx-Class.git throw exception for multi-has_many prefetch --- diff --git a/Changes b/Changes index 368e47d..c416169 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - throw a clear exception when user tries multi-has_many prefetch + - SQLT parser prefixes index names with ${table}_idx_ to avoid clashes - mark ResultSetManager as deprecated and undocument it - pod fix (RT #32988) - add Test::Exception to test requirements (RT #34256) diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index b723517..a026339 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -905,6 +905,16 @@ sub resolve_prefetch { $self->throw_exception( "Can't prefetch has_many ${pre} (join cond too complex)") unless ref($rel_info->{cond}) eq 'HASH'; + my $dots = @{[$as_prefix =~ m/\./g]} + 1; # +1 to match the ".${as_prefix}" + if (my ($fail) = grep { @{[$_ =~ m/\./g]} == $dots } + keys %{$collapse}) { + my ($last) = ($fail =~ /([^\.]+)$/); + $self->throw_exception( + "Can't prefetch multiple has_many rels ${last} and ${pre}" + .(length($as_prefix) ? "at the same level (${as_prefix})" + : "at top level" + )); + } #my @col = map { (/^self\.(.+)$/ ? ("${as_prefix}.$1") : ()); } # values %{$rel_info->{cond}}; $collapse->{".${as_prefix}${pre}"} = [ $rel_source->primary_columns ]; diff --git a/t/03podcoverage.t b/t/03podcoverage.t index cfa08de..c2c2560 100644 --- a/t/03podcoverage.t +++ b/t/03podcoverage.t @@ -76,6 +76,7 @@ my $exceptions = { 'DBIx::Class::Relationship::ManyToMany' => { skip => 1 }, 'DBIx::Class::Relationship::ProxyMethods' => { skip => 1 }, 'DBIx::Class::ResultSetProxy' => { skip => 1 }, + 'DBIx::Class::ResultSetManager' => { skip => 1 }, 'DBIx::Class::ResultSourceProxy' => { skip => 1 }, 'DBIx::Class::Storage::DBI' => { skip => 1 }, 'DBIx::Class::Storage::DBI::DB2' => { skip => 1 }, diff --git a/t/77prefetch.t b/t/77prefetch.t index a0ab5f2..8b3f10c 100644 --- a/t/77prefetch.t +++ b/t/77prefetch.t @@ -16,7 +16,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 58 ); + : ( tests => 50 ); } # figure out if we've got a version of sqlite that is older than 3.2.6, in @@ -346,7 +346,7 @@ is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no # once the following TODO is complete, remove the 2 stop-gap tests immediately after the TODO block # (the TODO block itself contains tests ensuring that the stop-gaps are removed) -TODO: { +TODO: if (0) { # broken-ass todo block commented out by mst local $TODO = 'Prefetch of multiple has_many rels at the same level (currently must die to protect the clueless git)'; use DBIx::Class::ResultClass::HashRefInflator;