
DM mistakes singular words for plural
Reported by lobo_tuerto | September 7th, 2008 @ 05:36 AM
Same as this: http://wm.lighthouseapp.com/proj...
But fails for the word Address.
Comments and changes to this ticket
-
Greg Campbell September 10th, 2008 @ 07:26 PM
This appears to be the case for any belongs_to or has_one relationship where the referenced model ends in "s". The bug linked to above was fixed by adding English::Inflect.singular_word "status", "status" to extlib, but I don't think that's scalable to the universe of singular words ending in "s": even user_status, for instance, will continue to fail. I'll dig into the code for a few minutes and attempt to ascertain how difficult this would be to fix.
-
Greg Campbell September 10th, 2008 @ 08:47 PM
- Tag changed from bug, dm-core, relationships to associations, bug, dm-core, relationships
After looking at the code, the problem appears to be that the association calls Extlib::Inflection.classify(), which singularizes the name passed in - this causes a problem for any already-singular associations to classes ending in "s". Active Record, in contrast, does the following:
class_name = name.to_s.camelize class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro) class_name
Potential fixes I can think of off the top of my head include:
- change classify() to take a second optional param (defaulting to false) indicating that the passed-in name is known to be singular already, as in the case of belongs_to and has 1
- change the associations in question to avoid using classify and do something
- pluralize the name before passing it in to classify (hack level: elevated)
- add a bunch of singularization rules to handle these sorts of scenarios, either in English or in Extlib (maybe the universe of singular words ending with "s" is smaller than I expect it to be?)
I haven't done any real hacking in the DataMapper codebase yet, so I'm not sure which of these is least impactful overall.
-
Greg Campbell September 10th, 2008 @ 08:49 PM
Apologies for the poor formatting above! Lighthouse really needs a preview button for comments.
-
Dan Kubb (dkubb) January 7th, 2009 @ 04:33 PM
- State changed from new to accepted
- Assigned user changed from Sam Smoot to Dan Kubb (dkubb)
I believe this is fixed in dkubb/dm-core. I will check and mark this as resolved if so.
-
Jonathan Stott (namelessjon) February 22nd, 2009 @ 08:52 AM
- Tag changed from associations, bug, dm-core, relationships to associations, bug, dm-core, one_file_test, relationships
- State changed from accepted to resolved
Fixed in 0.10.0 (see attached one file test)
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Referenced by
-
586 Associations singularizing an already singular string I believe this is the same issue reported in ticket #554....
-
708 belongs_to inflector behavior See #554
-
712 has 1 requires plural model name See #554