Subject: | DBIx::Class::Schema::Loader::RelBuilder and Lingua::EN::Inflect::Phrase |
Hi All,
I've found a strange behavior when trying to generate a static schema
for my Catalyst App. That's is the some relationship names are converted
incorrectly.
After dug up through the module and found that in package
DBIx::Class::Schema::Loader::RelBuilder, line 142 (_to_PL method), the
conversion process seems to be the source of problem.
Here is the code:
=============================
$name =~ s/_/ /g;
my $plural = Lingua::EN::Inflect::Phrase::to_PL($name);
$plural =~ s/ /_/g;
=============================
The code used Lingua::EN::Inflect::Phrase module to pluralize the table
name and before that it converted _ to space. The problem came here
since Lingua::EN::Inflect::Phrase module treated a phase as a sentence.
So I have some tables that belong to a "media" table with has_many
relationship.
One of my table name is "media_attribute", it converted to
"medias_attribute" that's wrong!, the right one should be
"media_attributes" since a media has_many attributes.
Strangely, other names are converted correctly e.g. "media_detail" and
"media_collection" are converted to "media_details" and
"media_collections".
To fix this problem my suggession is to not converting _ to space before
pluralize process, at least for has_many relationship.
The fixed code should be something like this:
=============================
#$name =~ s/_/ /g;
my $plural = Lingua::EN::Inflect::Phrase::to_PL($name);
$plural =~ s/ /_/g;
=============================
As the above code, when I pluralized "media_attribute" it produced the
right thing, "media_attributes".
Please concern my issue.
Thanks,
Chakkit