X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=d6c964278a701db93dbf712a32231ab47dbdd595;hp=a9d15cb251a82900c5af2390da32250993bef715;hb=6dda95db961112c4a422ebe282b6dfc7935be40e;hpb=d5109b4395d35a615f36fc7629803c24d489c516 diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index a9d15cb25..d6c964278 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -3040,6 +3040,22 @@ sub scalar_sql { defined($scalar) ? $scalar : ''; } +=item count [ WHERE ] + +Convenience method for the common case of "SELECT COUNT(*) FROM table", +with optional WHERE. Must be called as method on a class with an +associated table. + +=cut + +sub count { + my($self, $where) = (shift, shift); + my $table = $self->table or die 'count called on object of class '.ref($self); + my $sql = "SELECT COUNT(*) FROM $table"; + $sql .= " WHERE $where" if $where; + $self->scalar_sql($sql); +} + =back =head1 SUBROUTINES