summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2005-07-12 09:13:19 +0000
committerivan <ivan>2005-07-12 09:13:19 +0000
commit06707641b711d9218aba36dc70cf86146fa2acef (patch)
tree3fe9bcfdc54d43e559d778bb95ecf106e5436795 /FS
parent4def4da47df27f6982168220ec395e5580c32785 (diff)
patch from rjbs to add by_key contructor to Record.pm
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Record.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 5c8a322c9..f806e4f88 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -427,6 +427,34 @@ sub qsearch {
return @return;
}
+=item by_key PRIMARY_KEY_VALUE
+
+This is a class method that returns the record with the given primary key
+value. This method is only useful in FS::Record subclasses. For example:
+
+ my $cust_main = FS::cust_main->by_key(1); # retrieve customer with custnum 1
+
+is equivalent to:
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => 1 } );
+
+=cut
+
+sub by_key {
+ my ($class, $pkey_value) = @_;
+
+ my $table = $class->table
+ or croak "No table for $class found";
+
+ my $dbdef_table = $dbdef->table($table)
+ or die "No schema for table $table found - ".
+ "do you need to create it or run dbdef-create?";
+ my $pkey = $dbdef_table->primary_key
+ or die "No primary key for table $table";
+
+ return qsearchs($table, { $pkey => $pkey_value });
+}
+
=item jsearch TABLE, HASHREF, SELECT, EXTRA_SQL, PRIMARY_TABLE, PRIMARY_KEY
Experimental JOINed search method. Using this method, you can execute a