Posted about 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.

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
almost 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