From c09313030ba77f61771483e69179fd916d9328cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 20 Jun 2013 18:58:07 +0200 Subject: [PATCH] =?utf8?q?Rose=20Updatescript=20auf=20use=5Fsetup=20=3D>?= =?utf8?q?=200=20ge=C3=A4ndert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- scripts/rose_auto_create_model.pl | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index b5cdfba7d..3331c247e 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -95,7 +95,7 @@ sub process_table { __PACKAGE__->meta->schema('$schema'); CODE - my $definition = eval <meta->auto_initialize; - __PACKAGE__->meta->perl_class_definition(indent => 2); # , braces => 'bsd' CODE if ($EVAL_ERROR) { @@ -113,13 +112,26 @@ CODE return; } + my %args = (indent => 2, use_setup => 0); + + my $definition = "SL::DB::AUTO::$package"->meta->perl_class_definition(%args); + $definition =~ s/(__PACKAGE__->meta->initialize;)/# $1/; $definition =~ s/::AUTO::/::/g; - while (my ($auto_generated_name, $desired_name) = each %{ $foreign_key_name_map{$table} || {} }) { - $definition =~ s/( foreign_keys \s*=> \s*\[ .* ^\s+ ) ${auto_generated_name} \b/${1}${desired_name}/msx; + # patch foreign keys + my $foreign_key_definition = "SL::DB::AUTO::$package"->meta->perl_foreign_keys_definition(%args); + + if ($definition =~ /\Q$foreign_key_definition\E/) { + my ($start, $end) = ($-[0], $+[0]); + + while (my ($auto_generated_name, $desired_name) = each %{ $foreign_key_name_map{$table} || {} }) { + $foreign_key_definition =~ s/^ \s \s ${auto_generated_name} \b/ ${desired_name}/msx; + } + + substr($definition, $start, $end - $start) = $foreign_key_definition; } - $definition =~ s/(table\s*=>.*?\n)/$1 schema => '${schema}',\n/ if $schema; + $definition =~ s/(meta->table.*)\n/$1\n$schema_str/m if $schema; my $full_definition = <meta->initialize; + # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. __PACKAGE__->meta->make_manager_class; -- 2.20.1