From 0845c4b7d7a969d68cd55a15780c0af2fbe4d2db Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 22 Jan 2013 16:26:38 +0100 Subject: [PATCH] =?utf8?q?Rose:=20Fremdschl=C3=BCsselbenennung=20fixen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Die von Rose erzeugten Fremdschlüsselaccessoren heißen wie die Spaltennamen, also z.B. in Perl 'trans' zu Spalte 'trans_id'. Das ist unintuitiv und muss an vielen Stellen (z.B. bei den manager_args, with_objects etc.) auch als 'trans' angegeben werden. Also im Generatorscript gewisse Namen auf sinnvollere Namen mappen. --- SL/DB/DeliveryOrder.pm | 2 +- SL/DB/DeliveryOrderItem.pm | 5 ----- SL/DB/Invoice.pm | 5 ++--- SL/DB/InvoiceItem.pm | 5 ----- SL/DB/MetaSetup/DeliveryOrderItem.pm | 2 +- SL/DB/MetaSetup/Invoice.pm | 2 +- SL/DB/MetaSetup/InvoiceItem.pm | 2 +- SL/DB/MetaSetup/Order.pm | 2 +- SL/DB/MetaSetup/OrderItem.pm | 4 ++-- SL/DB/MetaSetup/PurchaseInvoice.pm | 2 +- SL/DB/Order.pm | 5 ++--- SL/DB/OrderItem.pm | 10 ---------- SL/DB/PurchaseInvoice.pm | 3 +-- scripts/rose_auto_create_model.pl | 15 +++++++++++++++ 14 files changed, 28 insertions(+), 36 deletions(-) diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index fda171a20..ca36cbda7 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -15,7 +15,7 @@ use List::Util qw(first); __PACKAGE__->meta->add_relationship(orderitems => { type => 'one to many', class => 'SL::DB::DeliveryOrderItem', column_map => { id => 'delivery_order_id' }, - manager_args => { with_objects => [ 'parts' ] } + manager_args => { with_objects => [ 'part' ] } }, ); diff --git a/SL/DB/DeliveryOrderItem.pm b/SL/DB/DeliveryOrderItem.pm index 433e676b0..d50a63ff4 100644 --- a/SL/DB/DeliveryOrderItem.pm +++ b/SL/DB/DeliveryOrderItem.pm @@ -24,9 +24,4 @@ __PACKAGE__->meta->initialize; # methods -sub part { - # canonial alias for parts. - goto &parts; -} - 1; diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index f75a6cd65..b164c0351 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -25,7 +25,7 @@ __PACKAGE__->meta->add_relationship( class => 'SL::DB::InvoiceItem', column_map => { id => 'trans_id' }, manager_args => { - with_objects => [ 'parts' ] + with_objects => [ 'part' ] } }, ); @@ -34,8 +34,7 @@ __PACKAGE__->meta->initialize; # methods -sub items { goto &invoiceitems; } -sub payment_term { goto &payment; } +sub items { goto &invoiceitems; } sub is_sales { # For compatibility with Order, DeliveryOrder diff --git a/SL/DB/InvoiceItem.pm b/SL/DB/InvoiceItem.pm index 36f0870d0..a4135fc4c 100644 --- a/SL/DB/InvoiceItem.pm +++ b/SL/DB/InvoiceItem.pm @@ -24,9 +24,4 @@ __PACKAGE__->meta->make_manager_class; __PACKAGE__->meta->initialize; -sub part { - # canonial alias for parts. - goto &parts; -} - 1; diff --git a/SL/DB/MetaSetup/DeliveryOrderItem.pm b/SL/DB/MetaSetup/DeliveryOrderItem.pm index 1e9a52be2..d5aaf3c79 100644 --- a/SL/DB/MetaSetup/DeliveryOrderItem.pm +++ b/SL/DB/MetaSetup/DeliveryOrderItem.pm @@ -45,7 +45,7 @@ __PACKAGE__->meta->setup( key_columns => { delivery_order_id => 'id' }, }, - parts => { + part => { class => 'SL::DB::Part', key_columns => { parts_id => 'id' }, }, diff --git a/SL/DB/MetaSetup/Invoice.pm b/SL/DB/MetaSetup/Invoice.pm index 1111a980b..b01b1417d 100644 --- a/SL/DB/MetaSetup/Invoice.pm +++ b/SL/DB/MetaSetup/Invoice.pm @@ -99,7 +99,7 @@ __PACKAGE__->meta->setup( key_columns => { language_id => 'id' }, }, - payment => { + payment_terms => { class => 'SL::DB::PaymentTerm', key_columns => { payment_id => 'id' }, }, diff --git a/SL/DB/MetaSetup/InvoiceItem.pm b/SL/DB/MetaSetup/InvoiceItem.pm index 470c4c4e6..eb5d84d2c 100644 --- a/SL/DB/MetaSetup/InvoiceItem.pm +++ b/SL/DB/MetaSetup/InvoiceItem.pm @@ -46,7 +46,7 @@ __PACKAGE__->meta->setup( allow_inline_column_values => 1, foreign_keys => [ - parts => { + part => { class => 'SL::DB::Part', key_columns => { parts_id => 'id' }, }, diff --git a/SL/DB/MetaSetup/Order.pm b/SL/DB/MetaSetup/Order.pm index 05512cd63..f68c276ef 100644 --- a/SL/DB/MetaSetup/Order.pm +++ b/SL/DB/MetaSetup/Order.pm @@ -93,7 +93,7 @@ __PACKAGE__->meta->setup( key_columns => { language_id => 'id' }, }, - payment => { + payment_terms => { class => 'SL::DB::PaymentTerm', key_columns => { payment_id => 'id' }, }, diff --git a/SL/DB/MetaSetup/OrderItem.pm b/SL/DB/MetaSetup/OrderItem.pm index 732d4c92e..3d0c98e7e 100644 --- a/SL/DB/MetaSetup/OrderItem.pm +++ b/SL/DB/MetaSetup/OrderItem.pm @@ -44,7 +44,7 @@ __PACKAGE__->meta->setup( allow_inline_column_values => 1, foreign_keys => [ - parts => { + part => { class => 'SL::DB::Part', key_columns => { parts_id => 'id' }, }, @@ -64,7 +64,7 @@ __PACKAGE__->meta->setup( key_columns => { project_id => 'id' }, }, - trans => { + order => { class => 'SL::DB::Order', key_columns => { trans_id => 'id' }, }, diff --git a/SL/DB/MetaSetup/PurchaseInvoice.pm b/SL/DB/MetaSetup/PurchaseInvoice.pm index 636a5d823..309884c68 100644 --- a/SL/DB/MetaSetup/PurchaseInvoice.pm +++ b/SL/DB/MetaSetup/PurchaseInvoice.pm @@ -75,7 +75,7 @@ __PACKAGE__->meta->setup( key_columns => { language_id => 'id' }, }, - payment => { + payment_terms => { class => 'SL::DB::PaymentTerm', key_columns => { payment_id => 'id' }, }, diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index ae5c5045d..b9959aa7e 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -23,7 +23,7 @@ __PACKAGE__->meta->add_relationship( class => 'SL::DB::OrderItem', column_map => { id => 'trans_id' }, manager_args => { - with_objects => [ 'parts' ] + with_objects => [ 'part' ] } }, periodic_invoices_config => { @@ -37,8 +37,7 @@ __PACKAGE__->meta->initialize; # methods -sub items { goto &orderitems; } -sub payment_terms { goto &payment; } +sub items { goto &orderitems; } sub type { my $self = shift; diff --git a/SL/DB/OrderItem.pm b/SL/DB/OrderItem.pm index f7ff3bbe6..862a215a1 100644 --- a/SL/DB/OrderItem.pm +++ b/SL/DB/OrderItem.pm @@ -39,14 +39,4 @@ sub shipped_qty { return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi); } -sub part { - # canonial alias for parts. - goto &parts; -} - -sub order { - # canonial alias for trans. - goto &trans; -} - 1; diff --git a/SL/DB/PurchaseInvoice.pm b/SL/DB/PurchaseInvoice.pm index 9ec6035b8..da34a27b8 100644 --- a/SL/DB/PurchaseInvoice.pm +++ b/SL/DB/PurchaseInvoice.pm @@ -19,8 +19,7 @@ __PACKAGE__->meta->add_relationship(invoiceitems => { type => 'one to ma __PACKAGE__->meta->initialize; -sub items { goto &invoiceitems; } -sub payment_term { goto &payment; } +sub items { goto &invoiceitems; } sub is_sales { # For compatibility with Order, DeliveryOrder diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index f7cc62d8a..20048f2d4 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -44,6 +44,16 @@ our $meta_path = "SL/DB/MetaSetup"; my %config; +our %foreign_key_name_map = ( + oe => { payment => 'payment_terms', }, + ar => { payment => 'payment_terms', }, + ap => { payment => 'payment_terms', }, + + orderitems => { parts => 'part', trans => 'order', }, + delivery_order_items => { parts => 'part' }, + invoice => { parts => 'part' }, +); + sub setup { SL::LxOfficeConf->read; @@ -103,6 +113,11 @@ CODE } $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; + } + my $full_definition = <