[Dbix-class] Fwd: DBIx::Class patch: better error diagnostics

Ash Berlin ash at cpan.org
Wed Dec 6 23:13:35 GMT 2006


Matt S Trout wrote:
> Somebody kick the tires at this and apply it if it seems sane please?
> 
> Begin forwarded message:
> 
>> From: Marc Espie <espie at nerim.net>
>> Date: 6 December 2006 15:12:15 GMT
>> To: mst at shadowcatsystems.co.uk
>> Subject: DBIx::Class patch: better error diagnostics
>> Reply-To: espie at nerim.net
>>
>> As I said in former messages, I'm (still) a novice to DBIx::Class, so I'm
>> probably qualified to comment on diagnostics ;-)
>>
>> Those two patches actually helped me set up my schema correctly (yes, 
>> they're
>> very simple).
>>
>> I've noticed that the primary key check is the same, so it probably means
>> some refactoring would help more, but those were a life-saver for me.
>>
>> --- lib/DBIx/Class/Relationship/HasMany.pm.orig    Wed Dec  6 15:56:28 
>> 2006
>> +++ lib/DBIx/Class/Relationship/HasMany.pm    Wed Dec  6 15:57:00 2006
>> @@ -16,6 +16,10 @@ sub has_many {
>>        "${class} has more"
>>      ) if $too_many;
>>
>> +    $class->throw_exception(
>> +      "has_many needs a primary key to infer a join; ".
>> +      "${class} has none"
>> +    ) if !defined $pri;
>>      my ($f_key,$guess);
>>      if (defined $cond && length $cond) {
>>        $f_key = $cond;
>> --- lib/DBIx/Class/Relationship/HasOne.pm.orig    Wed Dec  6 15:57:05 
>> 2006
>> +++ lib/DBIx/Class/Relationship/HasOne.pm    Wed Dec  6 15:58:09 2006
>> @@ -21,6 +21,10 @@ sub _has_one {
>>        "might_have/has_one can only infer join for a single primary 
>> key; ".
>>        "${class} has more"
>>      ) if $too_many;
>> +    $class->throw_exception(
>> +      "might_have/has_one needs a primary key  to infer a join; ".
>> +      "${class} has none"
>> +    ) if !defined $pri;
>>      my $f_class_loaded = eval { $f_class->columns };
>>      my ($f_key,$guess);
>>      if (defined $cond && length $cond) {
> 

Patches applied (with a slight modification) to trunk

Ash



More information about the Dbix-class mailing list