1 package SL::DB::Helper::ConventionManager;
5 use Rose::DB::Object::ConventionManager;
7 use base qw(Rose::DB::Object::ConventionManager);
9 sub auto_manager_class_name {
11 my $object_class = shift || $self->meta->class;
13 my @parts = split m/::/, $object_class;
14 my $last = pop @parts;
16 return join('::', @parts, 'Manager', $last);
19 # Base name used for 'make_manager_class', e.g. 'get_all',
21 sub auto_manager_base_name {
25 sub auto_manager_base_class {
26 return 'SL::DB::Helper::Manager';
29 sub auto_foreign_key_name
31 my($self, $f_class, $current_name, $key_columns, $used_names) = @_;
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;
37 if(keys %$key_columns == 1)
39 my($local_column, $foreign_column) = %$key_columns;
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)
45 $name = $local_column;
49 $name = $package_name || $current_name;
53 # Avoid method name conflicts
54 if($self->method_name_conflicts($name) || $used_names->{$name})
56 foreach my $s ('_obj', '_object')
58 # Try the name with a suffix appended
59 unless($self->method_name_conflicts($name . $s) ||
60 $used_names->{$name . $s})
68 # Give up and go with numbers...
69 $i++ while($self->method_name_conflicts($name . $i) ||
70 $used_names->{$name . $i});