If you use .sync
with sequlize and have a model name like User
, your database ends up with a table called Users
. More clearly, when you use the sequelize-cli model generator the generated file will show this pluralized table. Here is the code: (link)
What is Utils
?
* Note Sequelize has a directory called Utils
AND a file at lib/utils.js
.
What’s in lib/util.js
?
We find the function! This is how sequelize defines utils.pluralize
link
Util.pluralize IS inflection.pluralize
This is how its tested
What is inflection?
Inflection is a port of Ruby on Rails Active Support Inflection classes into JavaScript built by DreamersLab in Taipei. (link)
So how does sequelize/inflection pluralize?
Inflection seems to have rules based on:
- “uncountable words” that dont get pluralized like
tennis
orthunder
, - special words that have different pluralization rules
whereas
becomeswhereases
Eventually, inflection takes these rules, uses RegExp
and applies
them to your string. Theres a bunch of rules and at the end theres this
The common rule that is the exhausted else
or case default
rule that targets the end of the string with $
. No rules for that singular term? Add an s