Skip to content

AR::AttributeMethods#[] raises AM::AttributeMissingError for missing att... #8056

Merged
merged 1 commit into from Oct 28, 2012

2 participants

@frodsan
frodsan commented Oct 28, 2012

...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.

Francesco Rodriguez AR::AttributeMethods#[] raises AM::AttributeMissingError for missing …
…attributes.

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.
10f6f90
@frodsan
frodsan commented Oct 28, 2012

/cc @rafaelfranca Sorry for the previous PR, I think I forced push without a commit lulz.

@rafaelfranca rafaelfranca merged commit c82f0d7 into rails:master Oct 28, 2012
@bquorning bquorning referenced this pull request in bbatsov/rails-style-guide May 24, 2016
Open

`read_attribute(:attr)` and `self[:attr]` not equivalent #155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.