« They say we go through three career changes but really... | Main | svn:externals »

Perhaps Pluralize Means Something Other Than I Thought

Listen to this articleListen 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.

  1. To make plural.
  2. 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". ;-)

Hahaha...exactly! ;-)

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?).

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

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?

Faur enough. I'll make that change ASAP.

Cheers,

Simon

Ok, checked in a fix as suggested. Hope that works for you.

Cheers,

Simon

Like a charm.

Hope I'm not being too much of a nuisance :)

Thanks for your help.

Post a comment