summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2004-02-26 03:32:21 +0000
committerivan <ivan>2004-02-26 03:32:21 +0000
commitd6404e4599cded2b15c85b822008022593146d1b (patch)
tree6efd84d09d14fa340bbd465c07483a747acabf4b
parent64421a63575733bd52a4cb9b897f6847b4e14965 (diff)
allow replace with no arguments
-rw-r--r--FS/FS/Record.pm19
1 files changed, 18 insertions, 1 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 98acaf522..ee74d853c 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -622,7 +622,24 @@ returns the error, otherwise returns false.
=cut
sub replace {
- my ( $new, $old ) = ( shift, shift );
+ my $new = shift;
+
+ my $old;
+ if ( @_ ) {
+ $old = shift;
+ } else {
+ warn "[debug]$me replace called with no arguments; autoloading old record\n"
+ if $DEBUG;
+ my $primary_key = $new->dbdef_table->primary_key;
+ if ( $primary_key ) {
+ $old = qsearchs($new->table, { $primary_key => $new->$primary_key() } )
+ or croak "can't find ". $new->table. ".$primary_key ".
+ $new->$primary_key();
+ } else {
+ croak $new->table. " has no primary key; pass old record as argument";
+ }
+ }
+
warn "[debug]$me $new ->replace $old\n" if $DEBUG;
return "Records not in same table!" unless $new->table eq $old->table;