This project is archived and is in readonly mode.

#2286 ✓stale
Glenn Powell

Problem when mixing symbols/strings as association names

Reported by Glenn Powell | March 18th, 2009 @ 03:18 PM | in 3.x

I'm not sure if this is a bug, but I'm pretty sure it worked differently in previous Rails versions, and it isn't documented for 2.3.

When you create an association, it seems that you MUST use a Symbol as the name (not a String), since the build method in associations.rb (line 1833) calls: parent.reflections[associations.to_s.intern] The .intern will look only for associations named with the Symbol name. This is also true when using :through on subsequent has_one/many calls. (The through name MUST be a Symbol).

I'm fairly certain this has changed now in Rails 2.3, since some classes of mine were using Strings before without a problem. In my opinion, this should be simply remedied by having the has_one/many call convert the name to a Symbol automatically. (Along with any method that takes the name of an association). This would allow programmers to use either form. But even if Rails isn't altered to allow for String names, I think this should be documented in the Rails 2.3 release notes.


Comments and changes to this ticket

  • Steve St. Martin

    Steve St. Martin April 15th, 2010 @ 10:00 PM

    • Assigned user set to “Ryan Bigg”

    Please provide a patch. mark as incomplete

  • Ryan Bigg

    Ryan Bigg April 15th, 2010 @ 10:36 PM

    • State changed from “new” to “incomplete”

    Yes, patch welcomed.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:53 PM

    • State changed from “incomplete” to “open”
    • Tag changed from 2.3.2, association, associations, has_many, has_many_through, has_one, has_one_through to 232, association, associations, has_many, has_many_through, has_one, has_one_through
    • Importance changed from “” to “”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:53 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket