Associations named using a string cannot be included in a scope

Updated . Posted . Visible to the public.

If you defined your association via

class Article
  belongs_to "category"
end

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  
Martin Straub
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Martin Straub to makandra dev (2012-01-27 16:10)