diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/singular_association.rb | 13 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_one_associations_test.rb | 9 |
2 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb index 06a414b874..62d48d3a2c 100644 --- a/activerecord/lib/active_record/associations/builder/singular_association.rb +++ b/activerecord/lib/active_record/associations/builder/singular_association.rb @@ -13,6 +13,19 @@ module ActiveRecord::Associations::Builder private + def define_readers + super + name = self.name + + model.redefine_method("#{name}_loaded?") do + ActiveSupport::Deprecation.warn( + "Calling obj.#{name}_loaded? is deprecated. Please use " \ + "obj.association(:#{name}).loaded? instead." + ) + association(name).loaded? + end + end + def define_constructors name = self.name diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index f3c96ccbe6..625515f4f1 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -359,4 +359,13 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert_equal pirate.id, ships(:black_pearl).reload.pirate_id assert_nil new_ship.pirate_id end + + def test_deprecated_association_loaded + firm = companies(:first_firm) + firm.association(:account).stubs(:loaded?).returns(stub) + + assert_deprecated do + assert_equal firm.association(:account).loaded?, firm.account_loaded? + end + end end |