aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-09-04 18:55:30 +0000
committerRick Olson <technoweenie@gmail.com>2006-09-04 18:55:30 +0000
commitd52cee3e3bb4c45bfd21d3f905e502fa00758def (patch)
treefb633953345af08b5dd699f15016db6b4f31bd0f /activerecord
parent2e0927282d6986122ac260f3c23f601fe6043c05 (diff)
downloadrails-d52cee3e3bb4c45bfd21d3f905e502fa00758def.tar.gz
rails-d52cee3e3bb4c45bfd21d3f905e502fa00758def.tar.bz2
rails-d52cee3e3bb4c45bfd21d3f905e502fa00758def.zip
Add deprecation warning for inferred foreign key. #6029 [Josh Susser]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4992 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb6
-rwxr-xr-xactiverecord/test/associations_test.rb7
3 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index c0815198c2..5a1419415b 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add deprecation warning for inferred foreign key. #6029 [Josh Susser]
+
* 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]
* Deprecation: use :dependent => :delete_all rather than :exclusively_dependent => true. #6024 [Josh Susser]
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 0771f26218..33fd8afee2 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -655,6 +655,12 @@ module ActiveRecord
# :conditions => 'discounts > #{payments_count}'
# belongs_to :attachable, :polymorphic => true
def belongs_to(association_id, options = {})
+ if options.include?(:class_name) && !options.include?(:foreign_key)
+ ::ActiveSupport::Deprecation.warn(
+ "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.",
+ caller)
+ end
+
reflection = create_belongs_to_reflection(association_id, options)
if reflection.options[:polymorphic]
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index b6ffda8105..d7997beaa3 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -350,6 +350,13 @@ class HasOneAssociationsTest < Test::Unit::TestCase
end
end
+ def test_deprecated_inferred_foreign_key
+ assert_not_deprecated { Company.belongs_to :firm }
+ assert_not_deprecated { Company.belongs_to :client, :foreign_key => "firm_id" }
+ assert_not_deprecated { Company.belongs_to :firm, :class_name => "Firm", :foreign_key => "client_of" }
+ assert_deprecated("inferred foreign_key name") { Company.belongs_to :client, :class_name => "Firm" }
+ end
+
end