Read more

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

Dominik Schöler
December 20, 2011Software engineer at makandra GmbH
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
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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.

Posted by Dominik Schöler to makandra dev (2011-12-20 11:38)