From 45119ead56cbc3b06daae7ea258b3839234e0b9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 24 Feb 2011 10:53:04 +0100 Subject: [PATCH] Indices auf OneToOne relationships werden jetzt mit Fehler quittiert. --- SL/Helper/Csv/Dispatcher.pm | 19 +++++++++++++++---- t/helper/csv.t | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/SL/Helper/Csv/Dispatcher.pm b/SL/Helper/Csv/Dispatcher.pm index 31c5eba58..9626fed25 100644 --- a/SL/Helper/Csv/Dispatcher.pm +++ b/SL/Helper/Csv/Dispatcher.pm @@ -87,10 +87,21 @@ sub make_spec { for my $step_index ( split /\.(?!\d)/, $path ) { my ($step, $index) = split /\./, $step_index; if ($cur_class->can($step)) { - if ($cur_class->meta->relationship($step)) { #a - my $next_class = $cur_class->meta->relationship($step)->class; - push @{ $spec->{steps} }, [ $step, $next_class, $index ]; - $cur_class = $next_class; + if (my $rel = $cur_class->meta->relationship($step)) { #a + if ($index && ! $rel->isa('Rose::DB::Object::Metadata::Relationship::OneToMany')) { + $self->_push_error([ + $path, + undef, + "Profile path error. Indexed relationship is not OneToMany around here: '$step_index'", + undef, + 0, + ]); + return; + } else { + my $next_class = $cur_class->meta->relationship($step)->class; + push @{ $spec->{steps} }, [ $step, $next_class, $index ]; + $cur_class = $next_class; + } } else { # simple dispatch push @{ $spec->{steps} }, [ $step ]; last; diff --git a/t/helper/csv.t b/t/helper/csv.t index 7ac728f26..072143480 100644 --- a/t/helper/csv.t +++ b/t/helper/csv.t @@ -1,4 +1,4 @@ -use Test::More tests => 29; +use Test::More tests => 31; use SL::Dispatcher; use Data::Dumper; use utf8; @@ -208,4 +208,19 @@ is $csv->get_objects->[0]->makemodels->[0]->make, '213', '...check 2'; is $csv->get_objects->[0]->makemodels->[1]->model, 'Table 15', '...check 3'; is $csv->get_objects->[0]->makemodels->[1]->make, '523', '...check 4'; +###### + +$csv = SL::Helper::Csv->new( + file => \< '1,000.00', + class => 'SL::DB::Part', + profile => { + buchungsgruppe => "buchungsgruppen.1.description", + } +); +is $csv->parse, undef, 'wrong profile gets rejected'; +is_deeply $csv->errors, [ 'buchungsgruppen.1.description', undef, "Profile path error. Indexed relationship is not OneToMany around here: 'buchungsgruppen.1'", undef ,0 ], 'error indicates wrong header'; + # vim: ft=perl -- 2.20.1