Comments and changes to this ticket
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.
- 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.