From 842a2e4c7680cb09fae1522839502288df23b1c9 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 20 Dec 2017 15:29:09 +0100 Subject: [PATCH] Presenter: richtige Presenter-Klasse bei DB-Klassen Customer/Vendor laden --- SL/DB/Object.pm | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index c258761d1..52e9ec930 100755 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -22,6 +22,11 @@ my @rose_reserved_methods = qw( not_found save update import ); +my %db_to_presenter_mapping = ( + Customer => 'CustomerVendor', + Vendor => 'CustomerVendor', +); + sub new { my $class = shift; my $self = $class->SUPER::new(); @@ -240,16 +245,13 @@ sub clone_and_reset { } sub presenter { - my ($class_or_self) = @_; - - if (ref $class_or_self) { - my $class = ref $class_or_self; - $class =~ s{^SL::DB::}{SL::Presenter::}; - return SL::DB::Helper::Presenter->new($class, $class_or_self); - } else { - $class_or_self =~ s{^SL::DB::}{SL::Presenter::}; - return $class_or_self; - } + my ($self) = @_; + + my $class = ref $self; + $class =~ s{^SL::DB::}{}; + $class = "SL::Presenter::" . ($db_to_presenter_mapping{$class} // $class); + + return SL::DB::Helper::Presenter->new($class, $self); } sub as_debug_info { -- 2.20.1