Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 28, 2012
Merged

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

merged 1 commit into from
Oct 28, 2012

Conversation

frodsan
Copy link
Contributor

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

…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.
@frodsan
Copy link
Contributor Author

frodsan commented Oct 28, 2012

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

rafaelfranca added a commit that referenced this pull request Oct 28, 2012
AR::AttributeMethods#[] raises AM::AttributeMissingError for missing attributes
@rafaelfranca rafaelfranca merged commit c82f0d7 into rails:master Oct 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

relations should raise MissingAttributeError if the key is not loaded
2 participants