mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20578 from dcrec1/regression
raise ActiveModel::MissingAttributeError when trying to access a relationship without the foreign key attribute
This commit is contained in:
commit
af01f45f06
2 changed files with 5 additions and 1 deletions
|
@ -107,7 +107,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def stale_state
|
||||
result = owner._read_attribute(reflection.foreign_key)
|
||||
result = owner._read_attribute(reflection.foreign_key) { |n| owner.send(:missing_attribute, n, caller) }
|
||||
result && result.to_s
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,6 +31,10 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|||
assert_equal companies(:first_firm).name, firm.name
|
||||
end
|
||||
|
||||
def test_missing_attribute_error_is_raised_when_no_foreign_key_attribute
|
||||
assert_raises(ActiveModel::MissingAttributeError) { Client.select(:id).first.firm }
|
||||
end
|
||||
|
||||
def test_belongs_to_does_not_use_order_by
|
||||
ActiveRecord::SQLCounter.clear_log
|
||||
Client.find(3).firm
|
||||
|
|
Loading…
Reference in a new issue