On Fri, Oct 16, 2009 at 7:31 AM, J. Shirley <jshir...@gmail.com> wrote:


> What database do you use?  In MySQL and SQLite I get no exception at all:
>

Postgresql.


>
> $ perl -Ilib -e 'use MyApp; my $obj =
> MyApp->model('Schema::User')->find("bogus"); print "defined? " . ( defined
> $obj ? "yes" : "no" ) . "\n"';
>  no
>

 DBIx::Class::ResultSet::find(): DBI Exception: DBD::Pg::st execute failed:
ERROR:  invalid input syntax for integer: "bogus" [for Statement "SELECT
me.id ...

sub safe_find {
>     my ( $self, $id ) = @_;
>     if ( $id =~ /^(\d+)$/ ) {
>          return $self->find($1);
>     }
>     die "I pity the fool";
> }
>

Yes, that's one approach.    But, I'm not sure I can think of a reason why I
would not want to always do that, so might as well just override find (or
really search_rs, as that is what is called by find) and check id (or ids)
there.  But, there need to think about "where", "columns", and so on.



-- 
Bill Moseley
mose...@hank.org
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to