Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4992

Show
Ignore:
Timestamp:
09/04/06 18:55:30 (2 years ago)
Author:
rick
Message:

Add deprecation warning for inferred foreign key. #6029 [Josh Susser]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r4990 r4992  
    11*SVN* 
     2 
     3* Add deprecation warning for inferred foreign key. #6029 [Josh Susser] 
    24 
    35* Fixed the Ruby/MySQL adapter we ship with Active Record to work with the new authentication handshake that was introduced in MySQL 4.1, along with the other protocol changes made at that time #5723 [jimw@mysql.com] 
  • trunk/activerecord/lib/active_record/associations.rb

    r4981 r4992  
    656656      #   belongs_to :attachable, :polymorphic => true 
    657657      def belongs_to(association_id, options = {}) 
     658        if options.include?(:class_name) && !options.include?(:foreign_key) 
     659          ::ActiveSupport::Deprecation.warn( 
     660          "The inferred foreign_key name will change in Rails 2.0 to use the association name instead of its class name when they differ.  When using :class_name in belongs_to, use the :foreign_key option to explicitly set the key name to avoid problems in the transition.", 
     661          caller) 
     662        end 
     663         
    658664        reflection = create_belongs_to_reflection(association_id, options) 
    659665         
  • trunk/activerecord/test/associations_test.rb

    r4981 r4992  
    351351  end 
    352352   
     353  def test_deprecated_inferred_foreign_key 
     354    assert_not_deprecated { Company.belongs_to :firm } 
     355    assert_not_deprecated { Company.belongs_to :client, :foreign_key => "firm_id" } 
     356    assert_not_deprecated { Company.belongs_to :firm, :class_name => "Firm", :foreign_key => "client_of" } 
     357    assert_deprecated("inferred foreign_key name") { Company.belongs_to :client, :class_name => "Firm" } 
     358  end 
     359 
    353360end 
    354361