1 package SL::DB::Helpers::Mappings;
5 use Exporter qw(import);
7 our @EXPORT_OK = qw(db);
9 # these will not be managed as Rose::DB models, because they are not normalized
10 # significant changes are needed to get them done.
11 my @lxoffice_blacklist_permanent = qw(
12 acc_trans audittrail customertax datev defaults department dpt_trans
13 exchangerate finanzamt follow_up_access gifi inventory leads licenseinvoice
14 makemodel partsgroup partstax prices record_links rmaitems status tax_zones
15 todo_user_config translation translation_payment_terms units_language
18 # these are not managed _yet_, but will hopefully at some point.
19 # if you are confident that one of these works, remove it here.
20 my @lxoffice_blacklist_temp = qw(
23 my @lxoffice_blacklist = (@lxoffice_blacklist_permanent, @lxoffice_blacklist_temp);
25 # map table names to their models.
26 # unlike rails we have no singular<->plural magic.
27 # remeber: tables should be named as the plural of the model name.
28 my %lxoffice_package_names = (
30 ap => 'purchase_invoice',
31 bank_accounts => 'bank_account',
32 buchungsgruppen => 'buchungsgruppe',
33 contacts => 'contact',
34 custom_variable_configs => 'custom_variable_config',
35 custom_variables => 'custom_variable',
36 custom_variables_validity => 'custom_variable_validity',
37 delivery_orders => 'delivery_order',
38 delivery_order_items => 'delivery_order_item',
41 dunning_config => 'dunning_config',
42 employee => 'employee',
43 follow_up_links => 'follow_up_link',
44 follow_ups => 'follow_up',
45 generic_translations => 'generic_translation',
46 gl => 'GLTransaction',
47 history_erp => 'history',
48 invoice => 'invoice_item',
49 language => 'language',
52 orderitems => 'order_item',
55 payment_terms => 'payment_term',
56 price_factors => 'price_factor',
57 pricegroup => 'pricegroup',
58 printers => 'Printer',
60 sepa_export => 'sepa_export',
61 sepa_export_items => 'sepa_export_item',
62 schema_info => 'schema_info',
69 return LXOFFICE => \@lxoffice_blacklist;
72 sub get_package_names {
73 return LXOFFICE => \%lxoffice_package_names;
78 my $lookup = $lxoffice_package_names{$_[0]} ||
79 plurify($lxoffice_package_names{singlify($_[0])});
81 for my $thing ($string, $lookup) {
83 # best guess? its already the name. like part. camelize it first
84 my $class = "SL::DB::" . camelify($thing);
85 return $class if defined *{ $class. '::' };
87 # next, someone wants a manager and pluralized.
88 my $manager = "SL::DB::Manager::" . singlify(camelify($thing));
89 return $manager if defined *{ $manager . '::' };
92 die "Can't resolve '$string' as a database model, sorry. Did you perhaps forgot to load it?";
97 $str =~ s/_+(.)/uc($1)/ge;
103 $str =~ s/(?<!^)\u(.)/'_' . lc($1)/ge;
125 SL::DB::Helpers::Mappings - Rose Table <-> Model mapping information
129 use SL::DB::Helpers::Mappings qw(@blacklist %table2model);
133 This modul stores table <-> model mappings used by the
134 L<scripts/rose_auto_create_model.pl> script. If you add a new table that has
135 custom mappings, add it here.
139 A special function provided here is E<db>. Without it you'd have to write:
141 my $part = SL::DB::Part->new(id => 1234);
142 my @all_parts = SL::DB::Manager::Part->get_all;
144 with them it becomes:
146 my $part = db('part')->new(id => 123);
147 my @all_parts = db('parts')->get_all;
149 You don't have to care about add that SL::DB:: incantation anymore. Also, a
150 simple s at the end will get you the associated Manager class.
152 db is written to try to make sense of what you give it, but if all fails, it
153 will die with an error.
161 L<scripts/rose_auto_create_model.pl>
165 Sven Schöling <s.schoeling@linet-services.de>