[Dbix-class] result testing

Matt S Trout dbix-class at trout.me.uk
Sun Dec 16 20:10:56 GMT 2007


On Tue, Dec 11, 2007 at 11:11:05AM +0200, Angel Kolev wrote:
> Hi guys.
> How i can check if my $rs = 
> $c->model('AppModelDB::Clients')->search({id=>$id}); succeed ?

If you're looking up by PK why not just use find() ?

> If i try "myErrorFunc() unless defined $rs->first->id" (or something 

if (my $client = $c->model('AppModelDB::Clients')->find({ id => $id })) {
  ... do stuff ...
} else {
  $self->handle_error;
}

Notes:

You're writing in an OO system, use methods not functions.

You're writing perl, use names_like_this not namesLikeJava.

If you actually -do- want an rs then if (defined $rs->first) or if ($rs->count)
are sufficient.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list