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

Updated . Posted . Visible to the public.
Association named 'variations' was not found; perhaps you misspelled it?

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

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.

Profile picture of Dominik Schöler
Dominik Schöler
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2011-12-20 10:38)