Perhaps Pluralize Means Something Other Than I Thought
Listen to this article
Besides the unfortunate use of a z where there really ought to be an s (yes, yes, I'm Australian), what does this word really mean?
pluralize v. tr.
- To make plural.
- Grammar. To express in the plural.
OK, that's pretty much what I thought it meant. So then riddle me this Batman:
simon$ ./script/console Loading development environment. >> "country".pluralize => "countries" >>
Good good. Just as expected. So, now let's try something else:
>> "countries".pluralize => "country" >>
Huh??? Since when did country become the plural of countries?
Comments
Stupid pluralizer. Even I know it should be "countriesies". ;-)
Posted by: Niclas Nilsson | June 14, 2006 05:55 PM
Hahaha...exactly! ;-)
Posted by: Simon Harris
|
June 14, 2006 05:57 PM
Haha, that's the same test I tried when my foreign keys were failing and the same baffled feeling. For the foreign_key_migrations plugin, I just changed it to not pluralize the table name used in :references. I don't know if there are any better options (perhaps singularizing then pluralizing?).
Posted by: obrie572
|
June 16, 2006 01:59 AM
Hehe, yeah the funny thing is that singularize works as expected. Ie it doesn't turn country into countries, it leaves it as country. Anyway I've checked in a fix that calls singularize _before_ pluralize just in case. Pretty hacky but certainly the simplest thing that could possibly work.
HTH,
Simon
Posted by: Simon Harris
|
June 16, 2006 06:00 AM
Unfortunately, I have some more bad news...
"email_address".singularize => "email_addres"
"email_addres".pluralize => "email_addres"
Therefore...
"email_address".singularize.pluralize => "email_addres"
I think the problem here is the following:
(1) If :references is specified, then you should assume that the table name is already pluralized (safe assumption?) and use it as is in the query.
(2) If :references is not specified, pluralize the table name that is parsed on line 44.
What do you think?
Posted by: obrie572
|
June 23, 2006 08:54 AM
Faur enough. I'll make that change ASAP.
Cheers,
Simon
Posted by: Simon Harris
|
June 23, 2006 09:06 AM
Ok, checked in a fix as suggested. Hope that works for you.
Cheers,
Simon
Posted by: Simon Harris
|
June 23, 2006 11:25 AM
Like a charm.
Hope I'm not being too much of a nuisance :)
Thanks for your help.
Posted by: obrie572
|
June 23, 2006 12:02 PM