From: Peter Rabbitson Date: Wed, 24 Mar 2010 10:33:03 +0000 (+0000) Subject: Clearer 'no such rel' errors, correct exception on pkless prefetch X-Git-Tag: v0.08121~42 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=455a33cbbf34ec2e40402dbd5cd88c1f92ebac17;p=dbsrgits%2FDBIx-Class.git Clearer 'no such rel' errors, correct exception on pkless prefetch --- diff --git a/Changes b/Changes index a7b7337..ee2c97e 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,7 @@ Revision history for DBIx::Class whenever possible - Add has_relationship method to row objects - Fix regression in set_column on PK-less objects + - Better error text on malformed/missing relationships - Add POD about the significance of PK columns - Fix for SQLite to ignore the (unsupported) { for => ... } attribute diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 91c8a92..46f2d29 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1007,7 +1007,7 @@ sub _collapse_result { # without having to contruct the full hash if (keys %collapse) { - my %pri = map { ($_ => 1) } $self->result_source->primary_columns; + my %pri = map { ($_ => 1) } $self->result_source->_pri_cols; foreach my $i (0 .. $#construct_as) { next if defined($construct_as[$i][0]); # only self table if (delete $pri{$construct_as[$i][1]}) { diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index d872d1c..ebe2ff1 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -523,8 +523,8 @@ sub _pri_cols { my $self = shift; my @pcols = $self->primary_columns or $self->throw_exception (sprintf( - 'Operation requires a primary key to be declared on %s via set_primary_key', - ref $self, + "Operation requires a primary key to be declared on '%s' via set_primary_key", + $self->source_name, )); return @pcols; } @@ -1242,7 +1242,7 @@ sub _resolve_join { for my $rel (keys %$join) { my $rel_info = $self->relationship_info($rel) - or $self->throw_exception("No such relationship ${rel}"); + or $self->throw_exception("No such relationship '$rel' on " . $self->source_name); my $force_left = $parent_force_left; $force_left ||= lc($rel_info->{attrs}{join_type}||'') eq 'left'; @@ -1272,7 +1272,7 @@ sub _resolve_join { ); my $rel_info = $self->relationship_info($join) - or $self->throw_exception("No such relationship ${join}"); + or $self->throw_exception("No such relationship $join on " . $self->source_name); my $rel_src = $self->related_source($join); return [ { $as => $rel_src->from, @@ -1440,7 +1440,7 @@ sub _resolve_prefetch { my $as = shift @{$p->{-join_aliases}}; my $rel_info = $self->relationship_info( $pre ); - $self->throw_exception( $self->name . " has no such relationship '$pre'" ) + $self->throw_exception( $self->source_name . " has no such relationship '$pre'" ) unless $rel_info; my $as_prefix = ($alias =~ /^.*?\.(.+)$/ ? $1.'.' : ''); my $rel_source = $self->related_source($pre); @@ -1501,7 +1501,7 @@ Returns the result source object for the given relationship. sub related_source { my ($self, $rel) = @_; if( !$self->has_relationship( $rel ) ) { - $self->throw_exception("No such relationship '$rel'"); + $self->throw_exception("No such relationship '$rel' on " . $self->source_name); } return $self->schema->source($self->relationship_info($rel)->{source}); } @@ -1523,7 +1523,7 @@ Returns the class name for objects in the given relationship. sub related_class { my ($self, $rel) = @_; if( !$self->has_relationship( $rel ) ) { - $self->throw_exception("No such relationship '$rel'"); + $self->throw_exception("No such relationship '$rel' on " . $self->source_name); } return $self->schema->class($self->relationship_info($rel)->{source}); }