X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=e4bc6c562bc4d211a8b7bef05f031f1cefc8e545;hb=5697bba078d6f9e263775bc2d887cc1ce3ff873d;hp=598cb6a770e06445fa5234e442c73b978916fccd;hpb=f84042a59546eedba93a9d47c5d20fc28cb1e158;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 598cb6a77..e4bc6c562 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -2802,6 +2802,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