Revision 83a78eea
Von Sven Schöling vor mehr als 9 Jahren hinzugefügt
SL/DB/Helper/ConventionManager.pm | ||
---|---|---|
26 | 26 |
return 'SL::DB::Helper::Manager'; |
27 | 27 |
} |
28 | 28 |
|
29 |
sub auto_foreign_key_name |
|
30 |
{ |
|
31 |
my($self, $f_class, $current_name, $key_columns, $used_names) = @_; |
|
32 |
|
|
33 |
my $f_meta = $f_class->meta or return $current_name; |
|
34 |
my $package_name = SL::DB::Helper::Mappings::get_name_for_table($f_meta->table); |
|
35 |
my $name = $package_name || $current_name; |
|
36 |
|
|
37 |
if(keys %$key_columns == 1) |
|
38 |
{ |
|
39 |
my($local_column, $foreign_column) = %$key_columns; |
|
40 |
|
|
41 |
# Try to lop off foreign column name. Example: |
|
42 |
# my_foreign_object_id -> my_foreign_object |
|
43 |
if($local_column =~ s/_$foreign_column$//i) |
|
44 |
{ |
|
45 |
$name = $local_column; |
|
46 |
} |
|
47 |
else |
|
48 |
{ |
|
49 |
$name = $package_name || $current_name; |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
# Avoid method name conflicts |
|
54 |
if($self->method_name_conflicts($name) || $used_names->{$name}) |
|
55 |
{ |
|
56 |
foreach my $s ('_obj', '_object') |
|
57 |
{ |
|
58 |
# Try the name with a suffix appended |
|
59 |
unless($self->method_name_conflicts($name . $s) || |
|
60 |
$used_names->{$name . $s}) |
|
61 |
{ |
|
62 |
return $name . $s; |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
my $i = 1; |
|
67 |
|
|
68 |
# Give up and go with numbers... |
|
69 |
$i++ while($self->method_name_conflicts($name . $i) || |
|
70 |
$used_names->{$name . $i}); |
|
71 |
|
|
72 |
return $name . $i; |
|
73 |
} |
|
74 |
|
|
75 |
return $name; |
|
76 |
} |
|
77 |
|
|
29 | 78 |
1; |
Auch abrufbar als: Unified diff
ConventionManager: foreign_key Benennung
Der Standard Conventionmanager von Rose versucht irgendwelche
singular/plural Magic um aus dem key einen guten Namen zu kriegen.
Das klappt antürlich mal wieder nicht.
Wir haben aber einen besseren Mechanismus dafür,
SL::DB::Helper::Mappings.
Also werden jetzt die dafür benutzt.