Changeset 85


Ignore:
Timestamp:
05/10/09 20:09:30 (15 years ago)
Author:
nanardon
Message:
  • check object exist before returning an instance
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r82 r85  
    133133sub new { 
    134134    my ($class, $base, $id) = @_; 
     135    my $sth = $base->db->prepare_cached( 
     136        sprintf(q{select 1 from %s where %s = ?}, 
     137            $base->db->quote_identifier($class->object_table), 
     138            $base->db->quote_identifier($class->key_field), 
     139        ), 
     140    ); 
     141    my $count = $sth->execute($id); 
     142    $sth->finish; 
     143    $count == 1 or return; 
    135144    bless({ _id => $id, _base => $base }, $class); 
    136145} 
Note: See TracChangeset for help on using the changeset viewer.