4 ms·
Given the previous experience of authoring a popular ORM, why repeat the mistake of pluralization of table names from model names? I've always found this conve
by jsd1982 9y ago
Given the previous experience of authoring a popular ORM, why repeat the mistake of pluralization of table names from model names?
I've always found this convention to be problematic at best and I've learned to avoid it. Maintaining consistency of names inside and outside of code makes searches and references easier to follow without having to mentally (or even mechanically) expand the singular name to plural name or vice versa (say, in a scratch pad to compose a test query).
- steveklabnik 9y agoI guess not everyone considers that a mistake, but at least it's very easy to change; tack on a #[table_name="whatever"] and you're done. I'm not sure if there's a more global way, since I don't mind pluralization.
- jsd1982 9y agoYeah, it's just my opinion tempered with experience. Is the pluralization rule literally as simple as stated in the article, namely appending an 's' and calling it done? English is rarely so simple and there are tons of corner cases which is why I tend to frown on the pluralization rules that are unpredictable. Those must be a nightmare for English-as-a-second-language folks too.
- steveklabnik 9y agoOh yeah, I remember thanks to ActiveSupport::Inflector, heh. Yes: https://github.com/diesel-rs/diesel/blob/e52d1710d98a05c3aa4663017ec47dbb40e1d747/diesel_codegen/src/model.rs#L72-L76 https://github.com/diesel-rs/diesel/blob/e52d1710d98a05c3aa4... But it also converts CamelCase to snake_case: https://github.com/diesel-rs/diesel/blob/e52d1710d98a05c3aa4663017ec47dbb40e1d747/diesel_codegen/src/model.rs#L56-L70 https://github.com/diesel-rs/diesel/blob/e52d1710d98a05c3aa4...