vanstyn / RapidApp

Turnkey ajaxy webapps
http://rapi.io
Other
48 stars 15 forks source link

Different class names generated with rapidapp.pl and model_DB_updater.pl #184

Closed sammakkoinen closed 3 years ago

sammakkoinen commented 4 years ago

If tables in a MySQL database have names in plural (say, "test_items"), corresponding result classes generated by the initial run of rapidapp.pl in MyApp/DB/Result will also have names in plural: TestItems.pm. However, subsequent runs of devel/model_DB_updater.pl will generate classes with names in singular: TestItem.pm.

As far as I can tell, this happens because the default behavior (changing table names to singular) gets replaced in Catalyst::Helper::Model::DBIC::Schema::ForRapidDbic:

$loader_args->{moniker_map} = sub { 
  my $table = shift; $table =~ s{\+$}{_plus}; 
  join '', map ucfirst, split /[\W_]+/, lc $table 
};

The docs for DBIx::Class::Schema::Loader::Base may give some hint to a solution: a coderef assigned to moniker_map accepts 3 arguments:

so that we can possibly get the default moniker and apply further processing to it and not to the original table name (not tested).

vanstyn commented 4 years ago

@sammakkoinen - Would you care to submit a patch/fix in a PR? It seems you have a solid enough grasp of the issue