summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2004-02-26 03:32:16 +0000
committerivan <ivan>2004-02-26 03:32:16 +0000
commit1fe4c2f04162ea5082ded078ee9c1b8b4a86c4af (patch)
tree552f309c564b46497686f8b424dd3ad5103ef8cb
parent395e0a932b6728326f8f5242f7f0a82e2dac919d (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 b950e306b..4a3cbe791 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -806,7 +806,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;