Posted over 7 years ago. Visible to the public.

Bugfix: Rails 2 does not find an association when it is named with a string instead of a symbol

Copy
Association named 'variations' was not found; perhaps you misspelled it?

I just was hunting down a strange error with this model:

Copy
class Model placeholder = 'variations' has_many placeholder nested_scope :verbose, :include => :variations end

Everything, including Model.variations and Model.reflect_on_all_associations.map &:name did work (the latter returned [ :some_association, 'variations' ]).
Eventually, the quotes led me to the solution: I had to write has_many placeholder.to_sym.

When Rails can't find an association, make sure it's defined as symbol

Seemingly, that's a bug in Rails.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
over 5 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more