Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Problem when mixing symbols/strings as association names

#2286

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.

cheers

Reported by Glenn Powell · March 18th, 2009 @ 03:18 PM

State: stale
Milestone: 3.x
Assigned to: Ryan Bigg Ryan Bigg
Importance: none

Activity

  1. Steve St. Martin
    Steve St. Martin
    • Assigned user set to Ryan Bigg

    Please provide a patch. mark as incomplete

    April 15th, 2010 @ 10:00 PM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to incomplete

    Yes, patch welcomed.

    April 15th, 2010 @ 10:36 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:53 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:53 PM