summaryrefslogtreecommitdiff
path: root/FS/FS/Record.pm
diff options
context:
space:
mode:
authormark <mark>2012-01-18 02:48:03 +0000
committermark <mark>2012-01-18 02:48:03 +0000
commit5697bba078d6f9e263775bc2d887cc1ce3ff873d (patch)
tree2523653352b55604174c8c462089a685d567e9f5 /FS/FS/Record.pm
parent57fe641524a2e3057f577074b26ab75b24534bbc (diff)
search services by tower/sector, #15950
Diffstat (limited to 'FS/FS/Record.pm')
-rw-r--r--FS/FS/Record.pm16
1 files changed, 16 insertions, 0 deletions
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