Read more

Associations named using a string cannot be included in a scope

Martin Straub
January 27, 2012Software engineer at makandra GmbH

If you defined your association via

class Article
  belongs_to "category"
end
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

and you try

Article.scoped(:include => :category)

you will get an error message

in `preload_one_association': Association named 'category' was not found; perhaps you misspelled it? (ActiveRecord::ConfigurationError)

Solution

Always define your assocations via symbol

class Article
  belongs_to :category
end  
Posted by Martin Straub to makandra dev (2012-01-27 17:10)