From: G. Richardson Date: Thu, 28 Jul 2016 13:21:52 +0000 (+0200) Subject: Erzeugnisfremdschlüssel auf Artikel 2 X-Git-Tag: release-3.5.4~2170 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=10348b514ddb450a0ee23df36f7f4c4242989b3e;p=kivitendo-erp.git Erzeugnisfremdschlüssel auf Artikel 2 auch die Spalte id verlinken. Die Tabelle assembly ist etwas Banane und nicht gerade Rose-freundlich. * die Spalte id entspricht der id des eigentlichen Erzeugnisses, alle Artikel eines Erzeugnisses haben den gleichen Eintrag in id. * die Spalte assembly_id ist der Primary Key der Tabelle. * die Spalte parts_id entspricht der id der Ware, das Teil des Erzeugnisses ist. Ein besserer Name für die Tabelle wäre assembly_items. --- diff --git a/SL/DB/Assembly.pm b/SL/DB/Assembly.pm index 22312144c..767ba411b 100644 --- a/SL/DB/Assembly.pm +++ b/SL/DB/Assembly.pm @@ -7,14 +7,6 @@ use strict; use SL::DB::MetaSetup::Assembly; -__PACKAGE__->meta->add_relationships( - part => { - type => 'many to one', - class => 'SL::DB::Part', - column_map => { parts_id => 'id' }, - }, -); - # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. __PACKAGE__->meta->make_manager_class; diff --git a/SL/DB/MetaSetup/Assembly.pm b/SL/DB/MetaSetup/Assembly.pm index 373f54e6b..87ffae6e3 100644 --- a/SL/DB/MetaSetup/Assembly.pm +++ b/SL/DB/MetaSetup/Assembly.pm @@ -11,7 +11,7 @@ __PACKAGE__->meta->table('assembly'); __PACKAGE__->meta->columns( assembly_id => { type => 'serial', not_null => 1 }, bom => { type => 'boolean' }, - id => { type => 'integer' }, + id => { type => 'integer', not_null => 1 }, itime => { type => 'timestamp', default => 'now()' }, mtime => { type => 'timestamp' }, parts_id => { type => 'integer', not_null => 1 }, @@ -23,7 +23,12 @@ __PACKAGE__->meta->primary_key_columns([ 'assembly_id' ]); __PACKAGE__->meta->allow_inline_column_values(1); __PACKAGE__->meta->foreign_keys( - parts => { + assembly_part => { + class => 'SL::DB::Part', + key_columns => { id => 'id' }, + }, + + part => { class => 'SL::DB::Part', key_columns => { parts_id => 'id' }, }, diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index fd43a0506..36c78da38 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -75,6 +75,8 @@ our %foreign_key_name_map = ( periodic_invoices_configs => { oe_id => 'order', email_recipient_contact_id => 'email_recipient_contact' }, reconciliation_links => { acc_trans_id => 'acc_trans' }, + + assembly => { parts_id => 'part', id => 'assembly_part' }, }, ); diff --git a/sql/Pg-upgrade2/assembly_parts_foreign_key2.sql b/sql/Pg-upgrade2/assembly_parts_foreign_key2.sql new file mode 100644 index 000000000..4b4e21417 --- /dev/null +++ b/sql/Pg-upgrade2/assembly_parts_foreign_key2.sql @@ -0,0 +1,7 @@ +-- @tag: assembly_parts_foreign_key2 +-- @description: Erzeugnis erhält Fremdschlüssel auf parts + NOT NULL in Tabelle assembly +-- @depends: assembly_parts_foreign_key +-- @ignore: 0 + +ALTER TABLE assembly ADD FOREIGN KEY (id) REFERENCES parts(id); +ALTER TABLE assembly ALTER COLUMN id SET NOT NULL;