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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)