GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Say we have this class:
class Test < ActiveRecord::Base
The following line should raise ActiveModel::MissingAttributeError
instead it returns nil
(tested with rails 3.0.11)
I'm OK with a change like this, but it would have to be done in 4.0. @jonleighton @jeremy any opinion?
Just re-pinging @jeremy @jonleighton @tenderlove
I'm not sure. This is a grey area. Should a missing foreign key raise?
@jeremy I feel as though it should raise; given a person may not know what scope they are in, for me it would be unexpected behavior to have a nil object.
just verified the behavior on master and this seems to be implemented. If I'm not mistaken we can close this.
@steveklabnik I think we should reopen this:
 pry(main)> Rails.version
 pry(main)> Tag.select('id').first.person_id
ActiveModel::MissingAttributeError: missing attribute: person_id
from /Users/frodsan/Code/rails/activerecord/lib/active_record/attribute_methods/read.rb:96:in `block (2 levels) in read_attribute'
 pry(main)> Tag.select('id').first.person
@steveklabnik sorry for the false information, I miss-interpreted the issue 😟
@frodsan thanks for the validation!