#586 ✓resolved
nitsujw

Associations singularizing an already singular string

Reported by nitsujw | October 6th, 2008 @ 07:19 PM

When you have a model "Forum" and a model "Topic", and the association between the two is has n, :topics and belongs_to :forum

You get the following error when loading an app: Cannot find the parent_model Fora for Topic (NameError)

For some reason it is singularizing what is already singular ("forum").

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 6th, 2008 @ 08:27 PM

    • State changed from “new” to “open”
    • Tag changed from associations, extlib, inflection to associations, bug, extlib, inflection

    This is probably being caused by Extlib::Inflection.classify. It calls Extlib::Inflection.singularize on the stringified form of whatever is passed into it.

    In the case of ManyToOne and OneToOne associations, the name is going to be singular, so perhaps we should use Extlib::Inflection.camelize instead of classify. In the ManyToMany and OneToMany associations we can continue to use classify, since the name passed in should always be plural.

    The reason this problem started happening is because we recently updated merb_datamapper to initialize all the associations after all the models are loaded. The problem was actually always there in the code, you just probably never ran any code that would bring it to your attention.

  • Greg Campbell

    Greg Campbell October 7th, 2008 @ 02:36 PM

    I believe this is the same issue reported in ticket #554. Another possible fix (which I mentioned in that ticket) would be to change classify to take an optional param indicating whether the argument is known to be singular already, as in the case of ManyToOne and OneToOne relationships.

  • nitsujw

    nitsujw October 13th, 2008 @ 12:20 PM

    • Tag changed from associations, bug, extlib, inflection to associations, bug, extlib, inflection

    Added a patch for this bug

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 8th, 2009 @ 04:48 AM

    • State changed from “open” to “accepted”
    • Assigned user changed from “Sam Smoot” to “Dan Kubb (dkubb)”
  • Jonathan Stott (namelessjon)

    Jonathan Stott (namelessjon) February 22nd, 2009 @ 08:56 AM

    • Tag changed from associations, bug, extlib, inflection to associations, bug, extlib, inflection, one_file_test
    • 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.

New-ticket Create new ticket

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

Pages