use SL::DB::SchemaInfo;
 use SL::DB::SepaExport;
 use SL::DB::SepaExportItem;
+use SL::DB::SepaExportMessageId;
 use SL::DB::Shipto;
 use SL::DB::Status;
 use SL::DB::Tax;
 
   requirement_specs                    => 'RequirementSpec',
   sepa_export                    => 'sepa_export',
   sepa_export_items              => 'sepa_export_item',
+  sepa_export_message_ids        => 'SepaExportMessageId',
   schema_info                    => 'schema_info',
   shipto                         => 'shipto',
   status                         => 'status',
 
--- /dev/null
+# This file has been auto-generated only because it didn't exist.
+# Feel free to modify it at will; it will not be overwritten automatically.
+
+package SL::DB::Manager::SepaExportMessageId;
+
+use strict;
+
+use parent qw(SL::DB::Helper::Manager);
+
+sub object_class { 'SL::DB::SepaExportMessageId' }
+
+__PACKAGE__->make_manager_methods;
+
+1;
 
--- /dev/null
+# This file has been auto-generated. Do not modify it; it will be overwritten
+# by rose_auto_create_model.pl automatically.
+package SL::DB::SepaExportMessageId;
+
+use strict;
+
+use parent qw(SL::DB::Object);
+
+__PACKAGE__->meta->table('sepa_export_message_ids');
+
+__PACKAGE__->meta->columns(
+  id             => { type => 'serial', not_null => 1 },
+  message_id     => { type => 'text', not_null => 1 },
+  sepa_export_id => { type => 'integer', not_null => 1 },
+);
+
+__PACKAGE__->meta->primary_key_columns([ 'id' ]);
+
+__PACKAGE__->meta->foreign_keys(
+  sepa_export => {
+    class       => 'SL::DB::SepaExport',
+    key_columns => { sepa_export_id => 'id' },
+  },
+);
+
+1;
+;
 
-# This file has been auto-generated only because it didn't exist.
-# Feel free to modify it at will; it will not be overwritten automatically.
-
 package SL::DB::SepaExport;
 
 use strict;
 
 use SL::DB::MetaSetup::SepaExport;
 
+__PACKAGE__->meta->add_relationship(
+  message_ids  => {
+    type       => 'one to many',
+    class      => 'SL::DB::SepaExportMessageId',
+    column_map => { id => 'sepa_export_id' },
+  },
+);
+
 __PACKAGE__->meta->initialize;
 
-# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
 __PACKAGE__->meta->make_manager_class;
 
 1;
 
--- /dev/null
+# This file has been auto-generated only because it didn't exist.
+# Feel free to modify it at will; it will not be overwritten automatically.
+
+package SL::DB::SepaExportMessageId;
+
+use strict;
+
+use SL::DB::MetaSetup::SepaExportMessageId;
+use SL::DB::Manager::SepaExportMessageId;
+
+__PACKAGE__->meta->initialize;
+
+1;
 
 
 use Data::Dumper;
 use SL::DB::BankAccount;
+use SL::DB::SepaExport;
 use SL::Chart;
 use SL::CT;
 use SL::Form;
                                  'date_of_signature' => $item->{mandate_date_of_signature}, });
   }
 
+  # Store the message ID used in each of the entries in order to
+  # facilitate finding them by looking at bank statements.
+  foreach my $id (@ids) {
+    SL::DB::SepaExportMessageId->new(
+      sepa_export_id => $id,
+      message_id     => $message_id,
+    )->save;
+  }
+
   my $xml = $sepa_xml->to_xml();
 
   print $cgi->header('-type'                => 'application/octet-stream',
 
--- /dev/null
+-- @tag: sepa_contained_in_message_ids
+-- @description: SEPA: Feld zum Merken, in welchen XML-Dokumenten (MsgId) ein Export vorkam
+-- @depends: release_3_3_0
+CREATE TABLE sepa_export_message_ids (
+  id             SERIAL,
+  sepa_export_id INTEGER NOT NULL,
+  message_id     TEXT    NOT NULL,
+
+  PRIMARY KEY (id),
+  FOREIGN KEY (sepa_export_id) REFERENCES sepa_export (id) ON DELETE CASCADE
+);