[Dbix-class] wishlist: exceptions

Jesper Krogh jesper at krogh.cc
Fri Mar 31 20:40:13 CEST 2006


Mark Hedges wrote:
>>I don't think a database returning an empty result should throw an
>>exception, so checking for undef seems reasonable to me.
>>Adding an option to make an empty result be fatal might be possible, I
>>certainly wouldn't want it as the default behaviour.
> 
> The trouble is when I want to do $one->two->three->four and two 
> or three returns as undef because there is no value, then it 
> bombs.  An option would be nice. 

I have similar situations where I'd have a has-many relation where the
"many" table has a timestamp. Then I'l like to add a shortcut on

Artitst has_many Cd's.

$s->resultset("Artist")->lastcd();

That does just does

return $self->cds()->search({},{page => 1,rows => 1, order_by =>
"createtime desc"})->next();

Which fails horrible if there is no relation.... and I'd just like an
"undef" :-)

Anyway . it's just for convenience, adding af few more lines of code
solves the problem.

Jesper
-- 
Jesper Krogh, jesper at krogh.cc




More information about the Dbix-class mailing list