rails/rails — pull request #8056 by frodsan (2012-10-28 19:20:09+00:00)
Title: AR::AttributeMethods#[] raises AM::AttributeMissingError for missing att...

...ributes.

This fixes the following behaviour:

class Person < ActiveRecord::Base
belongs_to :company
end

# Before:
person = Person.select('id').first
person[:name] # => nil
person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
person[:company_id] # => nil
person.company # => nil

# After:
person = Person.select('id').first
person[:name] # => ActiveModel::MissingAttributeError: missing_attribute: name
person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
person.company # => ActiveModel::MissingAttributeError: missing_attribute: company_id

Fixes #5433.